Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to find if hostboot has transitioned control to host #63

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libphal/libphal.H
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions libphal/phal_pdbg.C
Original file line number Diff line number Diff line change
Expand Up @@ -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