Support for Self Save API in OPAL
v7 cover Support for Self Save API in OPAL
v6: https://lists.ozlabs.org/pipermail/skiboot/2020-March/016645.html
Changelog
v6 --> v7
1. Addressed comments from Gautham for reporting warnings and errors
Background
==========
The power management framework on POWER systems include core idle states that lose context. Deep idle states namely "winkle" on POWER8 and "stop4" and "stop5" on POWER9 can be entered by a CPU to save different levels of power, as a consequence of which all the hypervisor resources such as SPRs and SCOMs are lost.
For most SPRs, saving and restoration of content for SPRs and SCOMs is handled by the hypervisor kernel prior to entering an post exit from an idle state respectively. However, there is a small set of critical SPRs and XSCOMs that are expected to contain sane values even before the control is transferred to the hypervisor kernel at system reset vector.
For this purpose, microcode firmware provides a mechanism to restore values on certain SPRs. The communication mechanism between the hypervisor kernel and the microcode is a standard interface called sleep-winkle-engine (SLW) on Power8 and Stop-API on Power9 which is abstracted by OPAL calls from the hypervisor kernel. The Stop-API provides an interface known as the self-restore API, to which the SPR number and a predefined value to be restored on wake-up from a deep stop state is supplied.
Motivation to introduce a new Stop-API
======================================
The self-restore API expects not just the SPR number but also the value with which the SPR is restored. This is good for those SPRs such as HSPRG0 whose values do not change at runtime, since for them, the kernel can invoke the self-restore API at boot time once the values of these SPRs are determined.
However, there are use-cases where-in the value to be saved cannot be known or cannot be updated in the layer it currently is. The shortcomings and the new use-cases which cannot be served by the existing self-restore API, serves as motivation for a new API:
Shortcoming1:
------------
In a special wakeup scenario when a CPU is woken up in stop4/5 and after the task is done, the HCODE puts it back to stop. The value of PSSCR is passed to the HCODE via the self-restore API. The kernel currently provides the value of the deepest stop state due to being conservative. Thus if a core that was in stop4 was woken up due to special wakeup, the HCODE will now put it back to stop5 thus increasing the subsequent wakeup latency to ~200us.
A mechanism is needed in place to update the PSSCR value each time the core is woken up due to special wakeup.
Shortcoming2:
------------
The value of LPCR is dynamic based on if the CPU is entered a stop state during cpu idle versus cpu hotplug.
Today, an additional self-restore call is made before entering CPU-Hotplug to clear the PECE1 bit in stop-API so that if we are woken up by a special wakeup on an offlined CPU, we go back to stop with the the bit cleared.
There is a overhead of an extra call
New Use-case:
-------------
In the case where the hypervisor is running on an ultravisor environment, the boot time is too late in the cycle to make the self-restore API calls, as these cannot be invoked from an non-secure context anymore
To address these shortcomings, the firmware provides another API known as the self-save API. The self-save API only takes the SPR number as a parameter and will ensure that on wakeup from a deep-stop state the SPR is restored with the value that it contained prior to entering the deep-stop.
Contrast between self-save and self-restore APIs
================================================
Before entering
deep idle |---------------|
------------> | HCODE A |
| |---------------|
|---------| |
| CPU |----|
|---------| |
| |---------------|
|------------>| HCODE B |
On waking up |---------------|from deep idle
When a self-restore API is invoked, the HCODE inserts instructions into "HCODE B" region of the above figure to restore the content of the SPR to the said value. The "HCODE B" region gets executed soon after the CPU wakes up from a deep idle state, thus executing the inserted instructions, thereby restoring the contents of the SPRs to the required values.
When a self-save API is invoked, the HCODE inserts instructions into the "HCODE A" region of the above figure to save the content of the SPR into some location in memory. It also inserts instructions into the "HCODE B" region to restore the content of the SPR to the corresponding value saved in the memory by the instructions in "HCODE A" region.
Thus, in contrast with self-restore, the self-save API *does not* need a value to be passed to it, since it ensures that the value of SPR before entering deep stop is saved, and subsequently the same value is restored.
Self-save and self-restore are complementary features since, self-restore can help in restoring a different value in the SPR on wakeup from a deep-idle state than what it had before entering the deep idle state. This was used in POWER8 for HSPRG0 to distinguish a wakeup from Winkle vs Fastsleep.
Limitations of self-save
========================
Ideally all SPRs should be available for self-save, but HID0 is very tricky to implement in microcode due to various endianess quirks. Couple of implementation schemes were buggy and hence HID0 was left out to be self-restore only.
The fallout of this limitation is as follows:
* In Non PEF environment, no issue. Linux will use self-restore for HID0 as it does today and no functional impact.
* In PEF environment, the HID0 restore value is decided by OPAL during boot and it is setup for LE hypervisor with radix MMU. This is the default and current working configuration of a PEF environment. However if there is a change, then HV Linux will try to change the HID0 value to something different than what OPAL decided, at which time deep-stop states will be disabled under this new PEF environment.
A simple and workable design is achieved by scoping the power management deep-stop state support only to a known default PEF environment. Any deviation will affect *only* deep stop-state support (stop4,5) in that environment and not have any functional impediment to the environment itself.
In future, if there is a need to support changing of HID0 to various values under PEF environment and support deep-stop states, it can be worked out via an ultravisor call or improve the microcode design to include HID0 in self-save. These future scheme would be an extension and does not break or make the current implementation scheme redundant.
Design Choices
==============
Presenting the design choices in front of us:
Design-Choice 1:
----------------
Only expose one of self-save or self-restore for all the SPRs. Prefer Self-save
Pros:
- Simplifies the design heavily, since the Kernel can unambiguously make one API call for all the SPRs on discovering the presence of the API type.
Cons:
- Breaks backward compatibility if OPAL always chooses to expose only the self-save API as the older kernels assume the existence of self-restore.
- The set of SPRs supported by self-save and self-restore are not identical. Eg: HID0 is not supported by self-save API. PSSCR support via self-restore is not robust during special-wakeup.
- As discussed above, self-save and self-restore are complementary. Thus OPAL apriory choosing one over the other for all SPRs takes away the flexibility from the kernel.
Design-Choice 2:
----------------
Expose two arrays of SPRs: One set of SPRs that are supported by self-save. Another set of SPRs supported by self-restore. These two sets do not intersect. Further, if an SPR is supported by both self-save and self-restore APIs, expose it only via self-save.
Pros:
- For an SPR the choice for the kernel is unambiguous.
Cons:
- Breaks backward compatibility if OPAL always chooses to expose the legacy SPRs only via the self-save API as the older kernels assume the existence of self-restore.
- By making the decision early on, we take away the flexibility from the kernel to use an API of its choice for an SPR.
Design-Choice 3
---------------
Expose two arrays of SPRs. One set of SPRs that are supported by self-save API. Another set of SPRs supported by self-restore API. Let the kernel choose which API to invoke. Even if it wants to always prefer self-save over self-restore, let that be kernel's choice.
Pros:
- Keeps the design flexible to allow the kernel to take a decision based on its functional and performance requirements. Thus, the kernel for instance can make a choice to invoke self-restore API (when available) for SPRs whose values do not evolve at runtime, and invoke the self-save API (when available)
for SPRs whose values will change during runtime.
- Design is backward compatible with older kernels.
Cons:
- The Kernel code will have additional complexity for parsing two lists of SPRs and making a choice w.r.t invocation of a specific stop-api.
Patches Organization
====================
Design choice 3 has been chosen as an implementation to demonstrate in this patch series.
Patch 1:
Commit adds support calling into the self save firmware API. Also adds abstraction for making platform agnostic calls.
Patch 2:
Commit adds wrappers for the Self Save API for which an OPAL call can be made.
Patch 3:
Commit adds API to determine the version of the STOP API. This helps to identify support for self save in the firmware
Patch 4:
Commit adds device tree attributes to advertise self save and self restore functionality along with the register set as a bitmask currently supported in the firmware. It also uses the versioning API to determine support for the self-save feature as a whole.
Pratik Rajesh Sampat (2):
Self save API integration
Advertise the self-save and self-restore attributes in the device tree
Prem Shanker Jha (2):
Self Save: Introducing Support for SPR Self Save API to verify the STOP API and image compatibility
.../ibm,opal/power-mgt/self-restore.rst | 27 + .../ibm,opal/power-mgt/self-save.rst | 27 + doc/opal-api/opal-slw-self-save-reg-181.rst | 49 + doc/opal-api/opal-slw-set-reg-100.rst | 5 + doc/power-management.rst | 48 + hw/slw.c | 207 ++++ include/opal-api.h | 3 +- include/p9_stop_api.H | 122 ++- include/skiboot.h | 4 + libpore/p9_cpu_reg_restore_instruction.H | 11 +- libpore/p9_hcd_memmap_base.H | 7 + libpore/p9_stop_api.C | 964 ++++++++++-------- libpore/p9_stop_api.H | 141 ++- libpore/p9_stop_data_struct.H | 4 +- libpore/p9_stop_util.H | 27 +- 15 files changed, 1214 insertions(+), 432 deletions(-) create mode 100644 doc/device-tree/ibm,opal/power-mgt/self-restore.rst create mode 100644 doc/device-tree/ibm,opal/power-mgt/self-save.rst create mode 100644 doc/opal-api/opal-slw-self-save-reg-181.rst
Signature · 1 line
2.25.1
PATCH v7 1/4 Self Save: Introducing Support for SPR Self Save
From: Prem Shanker Jha <[email protected]>
The commit is a merger of commits that makes the following changes:
1. Commit fixes some issues with code found during integration test
- replacement of addi with xor instruction during self save API. - fixing instruction generation for MFMSR during self save - data struct updates in STOP API - error RC updates for hcode image build - HOMER parser updates. - removed self save support for URMOR and HRMOR - code changes for compilation with OPAL - populating CME Image header with unsecure HOMER address.
Key_Cronus_Test=PM_REGRESS
Change-Id: I7cedcc466267c4245255d8d75c01ed695e316720
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/66580
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/66587
2. The commit also incorporates changes that make STOP API project agnostic changes include defining wrapper functions which call legacy API. It also adds duplicate enum members which start with prefix PROC instead of P9.
Key_Cronus_Test=PM_REGRESS
Change-Id: If87970f3e8cf9b507f33eb1be249e03eb3836a5e
RTC: 201128
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/71307
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/71314
--- include/p9_stop_api.H | 79 +- libpore/p9_cpu_reg_restore_instruction.H | 4 + libpore/p9_stop_api.C | 954 +++++++++++++---------- libpore/p9_stop_api.H | 115 ++- libpore/p9_stop_data_struct.H | 4 +- libpore/p9_stop_util.H | 7 +- 6 files changed, 721 insertions(+), 442 deletions(-)
include/p9_stop_api.H +77 -2
@@ -63,6 +63,26 @@ typedef enum P9_STOP_SPR_PMCR = 884, // core register P9_STOP_SPR_HID = 1008, // core register P9_STOP_SPR_MSR = 2000, // thread register + + //enum members which are project agnostic + PROC_STOP_SPR_DAWR = 180, // thread register + PROC_STOP_SPR_CIABR = 187, // thread register + PROC_STOP_SPR_DAWRX = 188, // thread register + PROC_STOP_SPR_HSPRG0 = 304, // thread register + PROC_STOP_SPR_HRMOR = 313, // core register + PROC_STOP_SPR_LPCR = 318, // thread register + PROC_STOP_SPR_HMEER = 337, // core register + PROC_STOP_SPR_PTCR = 464, // core register + PROC_STOP_SPR_USPRG0 = 496, // thread register + PROC_STOP_SPR_USPRG1 = 497, // thread register + PROC_STOP_SPR_URMOR = 505, // core register + PROC_STOP_SPR_SMFCTRL = 511, // thread register + PROC_STOP_SPR_LDBAR = 850, // thread register + PROC_STOP_SPR_PSSCR = 855, // thread register + PROC_STOP_SPR_PMCR = 884, // core register + PROC_STOP_SPR_HID = 1008, // core register + PROC_STOP_SPR_MSR = 2000, // thread register + } CpuReg_t; /**
@@ -85,6 +105,8 @@ typedef enum STOP_SAVE_SCOM_ENTRY_UPDATE_FAILED = 12, STOP_SAVE_INVALID_FUSED_CORE_STATUS = 13, STOP_SAVE_FAIL = 14, // for internal failure within firmware. + STOP_SAVE_SPR_ENTRY_MISSING = 15, + STOP_SAVE_SPR_BIT_POS_RESERVE = 16, } StopReturnCode_t; /**
@@ -101,7 +123,20 @@ typedef enum P9_STOP_SCOM_RESET = 6, P9_STOP_SCOM_OR_APPEND = 7, P9_STOP_SCOM_AND_APPEND = 8, - P9_STOP_SCOM_OP_MAX = 9 + P9_STOP_SCOM_OP_MAX = 9, + + //enum members which are project agnostic + PROC_STOP_SCOM_OP_MIN = 0, + PROC_STOP_SCOM_APPEND = 1, + PROC_STOP_SCOM_REPLACE = 2, + PROC_STOP_SCOM_OR = 3, + PROC_STOP_SCOM_AND = 4, + PROC_STOP_SCOM_NOOP = 5, + PROC_STOP_SCOM_RESET = 6, + PROC_STOP_SCOM_OR_APPEND = 7, + PROC_STOP_SCOM_AND_APPEND = 8, + PROC_STOP_SCOM_OP_MAX = 9, + } ScomOperation_t; /**
@@ -114,9 +149,49 @@ typedef enum P9_STOP_SECTION_EQ_SCOM = 2, P9_STOP_SECTION_L2 = 3, P9_STOP_SECTION_L3 = 4, - P9_STOP_SECTION_MAX = 5 + P9_STOP_SECTION_MAX = 5, + + //enum members which are project agnostic + PROC_STOP_SECTION_MIN = 0, + PROC_STOP_SECTION_CORE_SCOM = 1, + PROC_STOP_SECTION_EQ_SCOM = 2, + PROC_STOP_SECTION_L2 = 3, + PROC_STOP_SECTION_L3 = 4, + PROC_STOP_SECTION_MAX = 5, + } ScomSection_t; + + +/** + * @brief List of major incompatibilities between API version. + * @note STOP APIs assumes a specific HOMER layout, certain + * level of CME-SGPE hcode and certain version of self-save restore + * binary. A mismatch can break STOP function. + */ + +/** + * @brief Summarizes bit position allocated to SPRs in save bit mask vector. + */ +typedef enum +{ + BIT_POS_CIABR = 0, + BIT_POS_DAWR = 1, + BIT_POS_DAWRX = 2, + BIT_POS_HSPRG0 = 3, + BIT_POS_LDBAR = 4, + BIT_POS_LPCR = 5, + BIT_POS_PSSCR = 6, + BIT_POS_MSR = 7, + BIT_POS_HID = 21, + BIT_POS_HMEER = 22, + BIT_POS_PMCR = 23, + BIT_POS_PTCR = 24, + BIT_POS_SMFCTRL = 28, + BIT_POS_USPRG0 = 29, + BIT_POS_USPRG1 = 30, +} SprBitPositionList_t; + #ifdef __cplusplus extern "C" { #endif
libpore/p9_cpu_reg_restore_instruction.H +4 -0
@@ -62,6 +62,10 @@ enum MTSPR_CONST1 = 467, MTMSRD_CONST1 = 178, MFSPR_CONST = 339, + BLR_INST = 0x4e800020, + MTSPR_BASE_OPCODE = 0x7c0003a6, + MFSPR_BASE_OPCODE = 0x7c0002a6, + ATTN_OPCODE = 0x00000200, OPCODE_18 = 18, SELF_SAVE_FUNC_ADD = 0x2300, SELF_SAVE_OFFSET = 0x180,
libpore/p9_stop_api.C +523 -431
1,124 lines not on this page · raw message
libpore/p9_stop_api.H +110 -5
157 lines not on this page · raw message
libpore/p9_stop_data_struct.H +2 -2
@@ -67,9 +67,9 @@ enum SIZE_PER_SPR_RESTORE_INST = ((4 * sizeof(uint8_t)) / sizeof(uint32_t)), MAX_THREAD_LEVEL_SPRS = 11, MAX_CORE_LEVEL_SPRS = 6, - MAX_SPR_BIT_POS = 31, + MAX_SPR_BIT_POS = 30, SPR_BIT_POS_8 = 8, - SPR_BIT_POS_19 = 19, + SPR_BIT_POS_20 = 20, SPR_BIT_POS_25 = 25, SPR_BIT_POS_27 = 27, };
libpore/p9_stop_util.H +5 -2
@@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2016,2017 */ +/* Contributors Listed Below - COPYRIGHT 2016,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */
@@ -95,7 +95,10 @@ typedef struct uint64_t cpmrMagicWord; uint32_t buildDate; uint32_t version; - uint8_t reserve1[7]; + uint8_t reserve1[4]; + uint8_t selfRestoreVer; + uint8_t stopApiVer; + uint8_t urmorFix; uint8_t fusedModeStatus; uint32_t cmeImgOffset; uint32_t cmeImgLength;
Signature · 1 line
2.25.1
PATCH v7 2/4 Self save API integration
In reply to Pratik Rajesh SampatThe commit makes the self save API available outside the firmware by defining an OPAL wrapper.
This wrapper has a similar interface to that of self restore and expects the cpu pir, SPR number, minus the value of that SPR to be passed in its paramters and returns OPAL_SUCCESS on success.
The commit also documents both the self-save and the self-restore API calls along with their working and usage.
--- doc/opal-api/opal-slw-self-save-reg-181.rst | 49 ++++++++++++ doc/opal-api/opal-slw-set-reg-100.rst | 5 ++ doc/power-management.rst | 48 +++++++++++ hw/slw.c | 89 +++++++++++++++++++++ include/opal-api.h | 3 +- include/p9_stop_api.H | 17 ++++ include/skiboot.h | 3 + 7 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 doc/opal-api/opal-slw-self-save-reg-181.rst
doc/opal-api/opal-slw-self-save-reg-181.rst new file +49 -0
@@ -0,0 +1,49 @@ +.. OPAL_SLW_SELF_SAVE_REG: + +OPAL_SLW_SELF_SAVE_REG +====================== + +.. code-block:: c + + #define OPAL_SLW_SELF_SAVE_REG 181 + + int64_t opal_slw_self_save_reg(uint64_t cpu_pir, uint64_t sprn); + +:ref:`OPAL_SLW_SELF_SAVE_REG` is used to inform low-level firmware to save +the current contents of the SPR before entering a state of loss and +also restore the content back on waking up from a deep stop state. + +An OPAL call `OPAL_SLW_SET_REG` exists which is similar in function as +saving and restoring the SPR, with one difference being that the value of the +SPR must also be supplied in the parameters. +Complete reference: doc/opal-api/opal-slw-set-reg-100.rst + +Parameters +---------- + +``uint64_t cpu_pir`` + This parameter specifies the pir of the cpu for which the call is being made. +``uint64_t sprn`` + This parameter specifies the spr number as mentioned in p9_stop_api.H + The list of SPRs supported is as follows. This list is suppiled through the + device tree: + P9_STOP_SPR_DAWR, + P9_STOP_SPR_HSPRG0, + P9_STOP_SPR_LDBAR, + P9_STOP_SPR_LPCR, + P9_STOP_SPR_PSSCR, + P9_STOP_SPR_MSR, + P9_STOP_SPR_HRMOR, + P9_STOP_SPR_HMEER, + P9_STOP_SPR_PMCR, + P9_STOP_SPR_PTCR + +Returns +------- + +:ref:`OPAL_UNSUPPORTED` + If spr restore is not supported by pore engine. +:ref:`OPAL_PARAMETER` + Invalid handle for the pir/chip +:ref:`OPAL_SUCCESS` + On success
doc/opal-api/opal-slw-set-reg-100.rst +5 -0
@@ -21,6 +21,11 @@ In Power 9, it uses p9_stop_save_cpureg(), api provided by self restore code, to inform the spr with their corresponding values with which they must be restored. +An OPAL call `OPAL_SLW_SELF_SAVE_REG` exists which is similar in function +saving and restoring the SPR, with one difference being that the value of the +SPR doesn't need to be passed in the parameters, only with the SPR number +the firmware can identify, save and restore the values for the same. +Complete reference: doc/opal-api/opal-slw-self-save-reg-181.rst Parameters ----------
doc/power-management.rst +48 -0
51 lines not on this page · raw message
hw/slw.c +89 -0
101 lines not on this page · raw message
include/opal-api.h +2 -1
@@ -227,7 +227,8 @@#define OPAL_SECVAR_ENQUEUE_UPDATE 178#define OPAL_PHB_SET_OPTION 179#define OPAL_PHB_GET_OPTION 180 -#define OPAL_LAST 180 +#define OPAL_SLW_SELF_SAVE_REG 181 +#define OPAL_LAST 181#define QUIESCE_HOLD 1/* Spin all calls at entry */ #define QUIESCE_REJECT 2/* Fail all calls with OPAL_BUSY */
include/p9_stop_api.H +17 -0
@@ -34,6 +34,8 @@ /// /// @file p9_stop_api.H /// @brief describes STOP API which create/manipulate STOP image. +/// This header need not be consistent, however is a subset of the +/// libpore/p9_stop_api.H counterpart /// // *HWP HW Owner : Greg Still <[email protected]> // *HWP FW Owner : Prem Shanker Jha <[email protected]>
@@ -58,6 +60,7 @@ typedef enum P9_STOP_SPR_HRMOR = 313, // core register P9_STOP_SPR_LPCR = 318, // thread register P9_STOP_SPR_HMEER = 337, // core register + P9_STOP_SPR_PTCR = 464, // core register P9_STOP_SPR_LDBAR = 850, // thread register P9_STOP_SPR_PSSCR = 855, // thread register P9_STOP_SPR_PMCR = 884, // core register
@@ -230,6 +233,20 @@ StopReturnCode_t p9_stop_save_scom( void* const i_pImage, const ScomOperation_t i_operation, const ScomSection_t i_section ); +/** + * @brief Facilitates self save and restore of a list of SPRs of a thread. + * @param[in] i_pImage points to the start of HOMER image of P9 chip. + * @param[in] i_pir PIR associated with thread + * @param[in] i_saveRegVector bit vector representing SPRs that needs to be restored. + * @return STOP_SAVE_SUCCESS if API succeeds, error code otherwise. + * @note SPR save vector is a bit vector. For each SPR supported, + * there is an associated bit position in the bit vector.Refer + * to definition of SprBitPositionList_t to determine bit position + * associated with a particular SPR. + */ +StopReturnCode_t +p9_stop_save_cpureg_control( void* i_pImage, const uint64_t i_pir, + const uint32_t i_saveRegVector ); #ifdef __cplusplus } // extern "C" }; // namespace stopImageSection ends
include/skiboot.h +3 -0
@@ -306,6 +306,9 @@ extern void nx_p9_rng_late_init(void);/* SLW reinit function for switching core settings */ extern int64_t slw_reinit (uint64_t flags); +/* Self save SPR before entering the stop state */ +extern int64_t opal_slw_self_save_reg (uint64_t cpu_pir,uint64_t sprn); +/* Patch SPR in SLW image */ extern int64_t opal_slw_set_reg (uint64_t cpu_pir,uint64_t sprn,uint64_t val);
Signature · 1 line
2.25.1
PATCH v7 3/4 API to verify the STOP API and image compatibility
In reply to Pratik Rajesh SampatFrom: Prem Shanker Jha <[email protected]>
Commit defines a new API primarily intended for OPAL to determine cpu register save API's compatibility with HOMER layout and self save restore. It can help OPAL determine if version of API integrated with OPAL is different from hostboot.
Change-Id: Ic0de45a336cfb8b6b6096a10ac1cd3ffbaa44fc0
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/77612
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/77614
--- include/p9_stop_api.H | 26 +++++++++++ libpore/p9_cpu_reg_restore_instruction.H | 7 ++- libpore/p9_hcd_memmap_base.H | 7 +++ libpore/p9_stop_api.C | 58 +++++++++++++++++++++++- libpore/p9_stop_api.H | 26 ++++++++++- libpore/p9_stop_util.H | 20 ++++---- 6 files changed, 131 insertions(+), 13 deletions(-)
include/p9_stop_api.H +26 -0
@@ -110,6 +110,7 @@ typedef enum STOP_SAVE_FAIL = 14, // for internal failure within firmware. STOP_SAVE_SPR_ENTRY_MISSING = 15, STOP_SAVE_SPR_BIT_POS_RESERVE = 16, + STOP_SAVE_API_IMG_INCOMPATIBLE = 18, } StopReturnCode_t; /**
@@ -164,6 +165,14 @@ typedef enum } ScomSection_t; +/** + * @brief versions pertaining relvant to STOP API. + */ +typedef enum +{ + STOP_API_VER = 0x00, + STOP_API_VER_CONTROL = 0x02, +} VersionList_t; /**
@@ -195,6 +204,14 @@ typedef enum BIT_POS_USPRG1 = 30, } SprBitPositionList_t; +typedef enum +{ + SMF_SUPPORT_MISSING_IN_HOMER = 0x01, + SELF_SUPPORT_MISSING_FOR_LE_HYP = 0x02, + IPL_RUNTIME_CPU_SAVE_VER_MISMATCH = 0x04, + SELF_RESTORE_VER_MISMATCH = 0x08, +} VersionIncompList_t; + #ifdef __cplusplus extern "C" { #endif
@@ -247,6 +264,15 @@ StopReturnCode_t p9_stop_save_scom( void* const i_pImage, StopReturnCode_t p9_stop_save_cpureg_control( void* i_pImage, const uint64_t i_pir, const uint32_t i_saveRegVector ); + +/** + * @brief verifies if API is compatible of current HOMER image. + * @param[in] i_pImage points to the start of HOMER image of P9 chip. + * @param[out] o_inCompVector list of incompatibilities found. + * @return STOP_SAVE_SUCCESS if if API succeeds, error code otherwise. + */ +StopReturnCode_t proc_stop_api_discover_capability( void* const i_pImage, uint64_t* o_inCompVector ); + #ifdef __cplusplus } // extern "C" }; // namespace stopImageSection ends
libpore/p9_cpu_reg_restore_instruction.H +6 -1
@@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2018 */ +/* Contributors Listed Below - COPYRIGHT 2015,2020 */ /* [+] International Business Machines Corp. */ /* */ /* */
@@ -69,6 +69,11 @@ enum OPCODE_18 = 18, SELF_SAVE_FUNC_ADD = 0x2300, SELF_SAVE_OFFSET = 0x180, + SKIP_SPR_REST_INST = 0x4800001c, //b . +0x01c + MFLR_R30 = 0x7fc802a6, + SKIP_SPR_SELF_SAVE = 0x3bff0020, //addi r31 r31, 0x20 + MTLR_INST = 0x7fc803a6, //mtlr r30 + BRANCH_BE_INST = 0x48000020, }; #define MR_R0_TO_R10 0x7c0a0378UL //mr r10 r0
libpore/p9_hcd_memmap_base.H +7 -0
@@ -444,6 +444,13 @@ HCD_CONST(CME_QUAD_PSTATE_SIZE, HALF_KB) HCD_CONST(CME_REGION_SIZE, (64 * ONE_KB)) + +// HOMER compatibility + +HCD_CONST(STOP_API_CPU_SAVE_VER, 0x02) +HCD_CONST(SELF_SAVE_RESTORE_VER, 0x02) +HCD_CONST(SMF_SUPPORT_SIGNATURE_OFFSET, 0x1300) +HCD_CONST(SMF_SELF_SIGNATURE, (0x5f534d46)) // Debug HCD_CONST(CPMR_TRACE_REGION_OFFSET, (512 * ONE_KB))
libpore/p9_stop_api.C +57 -1
70 lines not on this page · raw message
libpore/p9_stop_api.H +25 -1
@@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2018 */ +/* Contributors Listed Below - COPYRIGHT 2015,2020 */ /* [+] International Business Machines Corp. */ /* */ /* */
@@ -114,6 +114,7 @@ typedef enum STOP_SAVE_FAIL = 14, // for internal failure within firmware. STOP_SAVE_SPR_ENTRY_MISSING = 15, STOP_SAVE_SPR_BIT_POS_RESERVE = 16, + STOP_SAVE_API_IMG_INCOMPATIBLE = 18, } StopReturnCode_t; /**
@@ -198,6 +199,21 @@ typedef enum BIT_POS_USPRG1 = 30, } SprBitPositionList_t; +/** + * @brief List of major incompatibilities between API version. + * @note STOP APIs assumes a specific HOMER layout, certain + * level of CME-SGPE hcode and certain version of self-save restore + * binary. A mismatch can break STOP function. + */ + +typedef enum +{ + SMF_SUPPORT_MISSING_IN_HOMER = 0x01, + SELF_SUPPORT_MISSING_FOR_LE_HYP = 0x02, + IPL_RUNTIME_CPU_SAVE_VER_MISMATCH = 0x04, + SELF_RESTORE_VER_MISMATCH = 0x08, +} VersionIncompList_t; + #ifdef __cplusplus extern "C" {
@@ -341,6 +357,14 @@ StopReturnCode_t proc_stop_save_cpureg( void* const i_pImage, */ StopReturnCode_t proc_stop_init_self_save( void* const i_pImage, const uint32_t i_corePos ); +/** + * @brief verifies if API is compatible of current HOMER image. + * @param[in] i_pImage points to the start of HOMER image of P9 chip. + * @param[out] o_inCompVector list of incompatibilities found. + * @return STOP_SAVE_SUCCESS if if API succeeds, error code otherwise. + */ +StopReturnCode_t proc_stop_api_discover_capability( void* const i_pImage, uint64_t* o_inCompVector ); + #ifdef __cplusplus } // extern "C" }; // namespace stopImageSection ends
libpore/p9_stop_util.H +10 -10
@@ -72,18 +72,18 @@ namespace stopImageSection ( (((WORD) >> 8) & 0x00FF) | (((WORD) << 8) & 0xFF00) ) #define SWIZZLE_4_BYTE(WORD) \ - ( (((WORD) >> 24) & 0x000000FF) | (((WORD) >> 8) & 0x0000FF00) | \ - (((WORD) << 8) & 0x00FF0000) | (((WORD) << 24) & 0xFF000000) ) + ( (((WORD) & 0x000000FF) << 24) | (((WORD) & 0x0000FF00) << 8) | \ + (((WORD) & 0x00FF0000) >> 8) | (((WORD) & 0xFF000000) >> 24) ) #define SWIZZLE_8_BYTE(WORD) \ - ( (((WORD) >> 56) & 0x00000000000000FF) | \ - (((WORD) >> 40) & 0x000000000000FF00)| \ - (((WORD) >> 24) & 0x0000000000FF0000) | \ - (((WORD) >> 8) & 0x00000000FF000000) | \ - (((WORD) << 8) & 0x000000FF00000000) | \ - (((WORD) << 24) & 0x0000FF0000000000) | \ - (((WORD) << 40) & 0x00FF000000000000) | \ - (((WORD) << 56) & 0xFF00000000000000) ) + ( (((WORD) & 0x00000000000000ffULL) << 56) | \ + (((WORD) & 0x000000000000ff00ULL) << 40) | \ + (((WORD) & 0x0000000000ff0000ULL) << 24) | \ + (((WORD) & 0x00000000ff000000ULL) << 8) | \ + (((WORD) & 0x000000ff00000000ULL) >> 8) | \ + (((WORD) & 0x0000ff0000000000ULL) >> 24) | \ + (((WORD) & 0x00ff000000000000ULL) >> 40) | \ + (((WORD) & 0xff00000000000000ULL) >> 56) ) #endif /**
Signature · 1 line
2.25.1
PATCH v7 4/4 Advertise the self-save and self-restore attributes in the device tree
In reply to Pratik Rajesh SampatSupport for self save and self restore interface is advertised in the device tree, along with the list of SPRs it supports for each.
The Special Purpose Register identification is encoded in a 2048 bitmask structure, where each bit signifies the identification key of that SPR which is consistent with that of the POWER architecture set for that register.
--- .../ibm,opal/power-mgt/self-restore.rst | 27 ++++ .../ibm,opal/power-mgt/self-save.rst | 27 ++++ hw/slw.c | 118 ++++++++++++++++++ include/skiboot.h | 1 + 4 files changed, 173 insertions(+) create mode 100644 doc/device-tree/ibm,opal/power-mgt/self-restore.rst create mode 100644 doc/device-tree/ibm,opal/power-mgt/self-save.rst
doc/device-tree/ibm,opal/power-mgt/self-restore.rst new file +27 -0
@@ -0,0 +1,27 @@ +ibm,opal/power-mgt/self-restore device tree entries +=================================================== + +This node exports the bitmask representing the special purpose registers that +the self-restore API currently supports. + +Example: + +.. code-block:: dts + + self-restore { + sprn-bitmask = <0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x42010000 0x0 0x0 + 0x20000 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 + 0x0 0x0 0x100000 0x900000 0x0 0x0 0x530000 0x0 0x0 0x0 + 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 + 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 + 0x0 0x10000>; + phandle = <0x1c7>; + }; + +sprn-bitmask +------------ + +This property is a bitmask of of all the existing SPRs and if the SPR is +supported, the corresponding bit of the SPR number is set to 1. +The representation of the bits are left-right, i.e the MSB of the first +doubleword represants the 0th bit.
doc/device-tree/ibm,opal/power-mgt/self-save.rst new file +27 -0
@@ -0,0 +1,27 @@ +ibm,opal/power-mgt/self-save device tree entries +=================================================== + +This node exports the bitmask representing the special purpose registers that +the self-save API currently supports. + +Example: + +.. code-block:: dts + + self-save { + sprn-bitmask = <0x0 0x0 0x0 0x0 0x100000 0x0 0x0 0x0 0x42010000 0x0 0x0 + 0x20000 0x0 0x0 0x0 0x10000 0x0 0x0 0x0 0x0 0x0 0x0 0x0 + 0x0 0x0 0x0 0x100000 0x840000 0x0 0x0 0x0 0x0 0x0 0x0 + 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 + 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 + 0x0 0x10000>; + phandle = <0x1c8>; + }; + +sprn-bitmask +------------ + +This property is a bitmask of of all the existing SPRs and if the SPR is +supported, the corresponding bit of the SPR number is set to 1. +The representation of the bits are left-right, i.e the MSB of the first +doubleword represants the 0th bit.
hw/slw.c +118 -0
134 lines not on this page · raw message
include/skiboot.h +1 -0
@@ -209,6 +209,7 @@ extern void early_uart_init(void);extern void homer_init (void );extern void slw_init (void );extern void add_cpu_idle_state_properties (void ); +extern void add_cpu_self_save_restore_properties (void );extern void lpc_rtc_init (void );/* flash support */
Signature · 1 line
2.25.1
Excerpts from Pratik Rajesh Sampat's message of April 16, 2020 5:53 pm:
Quoted 40 lines
v6: https://lists.ozlabs.org/pipermail/skiboot/2020-March/016645.html
Changelog
v6 --> v7
1. Addressed comments from Gautham for reporting warnings and errorsBackground
==========The power management framework on POWER systems include core idle states that lose context. Deep idle states namely "winkle" on POWER8 and "stop4" and "stop5" on POWER9 can be entered by a CPU to save different levels of power, as a consequence of which all the hypervisor resources such as SPRs and SCOMs are lost.
For most SPRs, saving and restoration of content for SPRs and SCOMs is handled by the hypervisor kernel prior to entering an post exit from an idle state respectively. However, there is a small set of critical SPRs and XSCOMs that are expected to contain sane values even before the control is transferred to the hypervisor kernel at system reset vector.
For this purpose, microcode firmware provides a mechanism to restore values on certain SPRs. The communication mechanism between the hypervisor kernel and the microcode is a standard interface called sleep-winkle-engine (SLW) on Power8 and Stop-API on Power9 which is abstracted by OPAL calls from the hypervisor kernel. The Stop-API provides an interface known as the self-restore API, to which the SPR number and a predefined value to be restored on wake-up from a deep stop state is supplied.
Motivation to introduce a new Stop-API
======================================The self-restore API expects not just the SPR number but also the value with which the SPR is restored. This is good for those SPRs such as HSPRG0 whose values do not change at runtime, since for them, the kernel can invoke the self-restore API at boot time once the values of these SPRs are determined.
Quoted 4 lines
However, there are use-cases where-in the value to be saved cannot be known or cannot be updated in the layer it currently is. The shortcomings and the new use-cases which cannot be served by the existing self-restore API, serves as motivation for a new API:
Thanks for writing this up, it goes some way to help think about the feature.
Quoted 11 lines
Shortcoming1:
------------
In a special wakeup scenario when a CPU is woken up in stop4/5 and after the task is done, the HCODE puts it back to stop. The value of PSSCR is passed to the HCODE via the self-restore API. The kernel currently provides the value of the deepest stop state due to being conservative. Thus if a core that was in stop4 was woken up due to special wakeup, the HCODE will now put it back to stop5 thus increasing the subsequent wakeup latency to ~200us.
A mechanism is needed in place to update the PSSCR value each time the core is woken up due to special wakeup.
This seems like a shortcoming of the wakeup firmware that shouldn't need any APIs to the kernel to solve, but the whole deep sleep wakeup seems like a shortcoming so let's assume they won't do that for whatever reason, then how much of a problem is this really? Are special wakeups that frequent?
Quoted 9 lines
Shortcoming2:
------------
The value of LPCR is dynamic based on if the CPU is entered a stop state during cpu idle versus cpu hotplug.
Today, an additional self-restore call is made before entering CPU-Hotplug to clear the PECE1 bit in stop-API so that if we are woken up by a special wakeup on an offlined CPU, we go back to stop with the the bit cleared.
There is a overhead of an extra call
This is a self-restore call when we offline or online a CPU? That's not a real problem either, is it?
Quoted 7 lines
New Use-case:
-------------
In the case where the hypervisor is running on an ultravisor environment, the boot time is too late in the cycle to make the self-restore API calls, as these cannot be invoked from an non-secure context anymore
Quoted 6 lines
To address these shortcomings, the firmware provides another API known as the self-save API. The self-save API only takes the SPR number as a parameter and will ensure that on wakeup from a deep-stop state the SPR is restored with the value that it contained prior to entering the deep-stop.
If the ultravisor is deployed in production only systems where we don't use runtime deep-stop states, do we need to handle this case?
Thanks,
Nick