From eb51677b9a404047cded4aa9d28e8d87d2ebcc94 Mon Sep 17 00:00:00 2001 From: Deepa Karthikeyan Date: Tue, 26 Sep 2023 08:19:41 -0500 Subject: [PATCH] libphal: Add method to find if control transitioned to host Utilizing the xyz.openbmc_project.State.Host interface to ascertain the host's operational status becomes less accurate when transitioning from hostboot to host. During the period when host is initializing and not yet fully operational, the host state is erroneously presumed to be in hostboot. In situations where host encounters initial boot difficulties, and the watchdog time is hit as the boot up process has not completed within a specific time, this watchdog misinterprets the issue as a problem with hostboot. To address this, there exists a core scratch register that undergoes an update by hostboot just before transferring control to host. We have devised a method that leverages this register to determine whether the transition to host has already occurred. By implementing this functionality we can determine which booting subsystem is failed or stopped responding, and the dump can be extracted from the right subsystem. Signed-off-by: Deepa Karthikeyan --- libphal/libphal.H | 10 ++++++++++ libphal/phal_pdbg.C | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/libphal/libphal.H b/libphal/libphal.H index 554dd6c..993ee0b 100644 --- a/libphal/libphal.H +++ b/libphal/libphal.H @@ -271,6 +271,16 @@ void putCFAM(struct pdbg_target *proc, const uint32_t addr, const uint32_t val); */ bool isSbeVitalAttnActive(struct pdbg_target *proc); +/** + * @brief Check if Hostboot has completed and the control transistioned to + * Host + * + * @return true when we have moved to host + * @return false if there is any error in reading the scom address, + * consider control still in hostboot + */ +bool hasControlTransitionedToHost(); + } // namespace pdbg namespace dump diff --git a/libphal/phal_pdbg.C b/libphal/phal_pdbg.C index f825011..629493a 100644 --- a/libphal/phal_pdbg.C +++ b/libphal/phal_pdbg.C @@ -280,4 +280,28 @@ bool isSbeVitalAttnActive(struct pdbg_target *proc) return validAttn; } +bool hasControlTransitionedToHost() +{ + // Read the scratch register to find if the control has moved to host + auto pibTarget = pdbg_target_from_path(nullptr, "/proc0/pib"); + + uint64_t l_coreScratchRegData = 0xFFFFFFFFFFFFFFFFull; + // HB changes the below core scratch reg as one of the last instructions + // that is run, so if that is zero then we're in host (hypervisor) + uint64_t l_coreScratchRegAddr = 0x4602F489; + + // Is there any error in reading the scom address, consider control is + // in hostboot + if (pib_read(pibTarget, l_coreScratchRegAddr, &l_coreScratchRegData)) { + // If unable to read the register, by default consider the + // control is in hostboot + log(level::ERROR, "scom read error: 0x%X", + l_coreScratchRegAddr); + return false; + } + + // If the register reads zero, return control moved to host. + return (l_coreScratchRegData == 0); +} + } // namespace openpower::phal::pdbg