Skip to content

Commit

Permalink
Merge pull request #84 from devenrao/state
Browse files Browse the repository at this point in the history
cater for get and set sbe odyssey state
  • Loading branch information
aravynd authored Jan 25, 2024
2 parents be61a82 + ce489be commit fae88a6
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libpdbg/libpdbg_sbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ int sbe_dump(struct pdbg_target *target, uint8_t type, uint8_t clock, uint8_t fa
*/
int sbe_get_state(struct pdbg_target *target, enum sbe_state *state);

/**
* @brief Get odyssey sbe state
*
* Get the current state of odyssey SBE
*
* @param[in] target fsi target to operate on
* @param[out] state sbe state
*
* @return 0 on success, -1 on failure
*/
int sbe_ody_get_state(struct pdbg_target *fsi, enum sbe_state *state);

/**
* @brief Set sbe state
*
Expand All @@ -116,6 +128,18 @@ int sbe_get_state(struct pdbg_target *target, enum sbe_state *state);
*/
int sbe_set_state(struct pdbg_target *target, enum sbe_state state);

/**
* @brief Set odyssey sbe state
*
* Set the current state of odyssey SBE
*
* @param[in] fsi fsi target to operate on
* @param[in] state odyssey sbe state
*
* @return 0 on success, -1 on failure
*/
int sbe_ody_set_state(struct pdbg_target *fsi, enum sbe_state state);

/**
* @brief Check if IPL boot is complete
*
Expand Down
89 changes: 89 additions & 0 deletions libpdbg/sbe_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,43 @@ static int sbe_read_state_register(struct pdbg_target *pib, uint32_t *value)
return 0;
}

static int sbe_ody_read_msg_register(struct pdbg_target *fsi, uint32_t *value)
{
int rc;

assert(fsi);
assert(pdbg_target_is_class(fsi, "fsi-ody"));

if (pdbg_target_status(fsi) != PDBG_TARGET_ENABLED)
return -1;

rc = fsi_ody_read(fsi, SBE_MSG_REG, value);
if (rc) {
PR_NOTICE("Failed to read ody sbe mailbox register\n");
return rc;
}

return 0;
}

static int sbe_ody_read_state_register(struct pdbg_target *fsi, uint32_t *value)
{
int rc;

assert(fsi);
assert(pdbg_target_is_class(fsi, "fsi-ody"));

if (pdbg_target_status(fsi) != PDBG_TARGET_ENABLED)
return -1;

rc = fsi_ody_read(fsi, SBE_STATE_REG, value);
if (rc) {
PR_NOTICE("Failed to read ody sbe state register\n");
return rc;
}
return 0;
}

static int sbe_write_state_register(struct pdbg_target *pib, uint32_t value)
{
struct pdbg_target *fsi = pdbg_target_parent_virtual("fsi", pib);
Expand All @@ -328,6 +365,25 @@ static int sbe_write_state_register(struct pdbg_target *pib, uint32_t value)
return 0;
}

static int sbe_ody_write_state_register(struct pdbg_target *fsi, uint32_t value)
{
int rc;

assert(fsi);
assert(pdbg_target_is_class(fsi, "fsi-ody"));

if (pdbg_target_status(fsi) != PDBG_TARGET_ENABLED)
return -1;

rc = fsi_ody_write(fsi, SBE_STATE_REG, value);
if (rc) {
PR_NOTICE("Failed to write ody sbe state register\n");
return rc;
}

return 0;
}

int sbe_get_state(struct pdbg_target *pib, enum sbe_state *state)
{
union sbe_msg_register msg;
Expand All @@ -351,6 +407,27 @@ int sbe_get_state(struct pdbg_target *pib, enum sbe_state *state)
return 0;
}

int sbe_ody_get_state(struct pdbg_target *fsi, enum sbe_state *state)
{
union sbe_msg_register msg;
uint32_t value;
int rc;

rc = sbe_ody_read_state_register(fsi, &value);
if (rc)
return -1;
if (value == SBE_STATE_CHECK_CFAM) {
rc = sbe_ody_read_msg_register(fsi, &msg.reg);
if (rc)
return -1;
*state = msg.sbe_booted ? SBE_STATE_BOOTED : SBE_STATE_CHECK_CFAM;
} else {
*state = value;
}

return 0;
}

int sbe_set_state(struct pdbg_target *pib, enum sbe_state state)
{
uint32_t value = state;
Expand All @@ -363,6 +440,18 @@ int sbe_set_state(struct pdbg_target *pib, enum sbe_state state)
return 0;
}

int sbe_ody_set_state(struct pdbg_target *fsi, enum sbe_state state)
{
uint32_t value = state;
int rc;

rc = sbe_ody_write_state_register(fsi, value);
if (rc)
return -1;

return 0;
}

int sbe_is_ipl_done(struct pdbg_target *pib, bool *done)
{
union sbe_msg_register msg;
Expand Down
1 change: 1 addition & 0 deletions libpdbg/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ enum pdbg_target_status pdbg_target_probe_ody_ocmb(struct pdbg_target *target)
return PDBG_TARGET_NONEXISTENT;
}

fsitarget->status = PDBG_TARGET_ENABLED;
target->status = PDBG_TARGET_ENABLED;
pibtarget->status = PDBG_TARGET_ENABLED;
}
Expand Down

0 comments on commit fae88a6

Please sign in to comment.