From 087e04598ed74146c2f2eab5666cd4d4b53b6974 Mon Sep 17 00:00:00 2001 From: Anshuman Khandual Date: Wed, 13 Aug 2014 14:27:45 +0530 Subject: dpo: Add OPAL interface to access the DPO timeout This patch adds a OPAL interface to fetch the DPO timeout. This functionality is required to synchronously query Sapphire about how much seconds are remaining for a forced system shutdown which is useful in cases where the host has missed the OPAL_MSG_DPO for some reason like system boot, reboot or kexec operations. This ensures host can still query about the DPO timeout status and act. This patch also adds helper routine to convert time base into seconds. Signed-off-by: Anshuman Khandual Signed-off-by: Benjamin Herrenschmidt --- hw/fsp/fsp-dpo.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'hw') diff --git a/hw/fsp/fsp-dpo.c b/hw/fsp/fsp-dpo.c index 23ab1ba..94a705e 100644 --- a/hw/fsp/fsp-dpo.c +++ b/hw/fsp/fsp-dpo.c @@ -21,12 +21,33 @@ #include #include #include +#include #include #include #define PREFIX "FSPDPO: " +#define DPO_TIMEOUT 2700 /* 45 minutes in seconds */ static bool fsp_dpo_pending = false; +unsigned long fsp_dpo_init_tb = 0; + +/* + * OPAL DPO interface + * + * Returns zero if DPO is not active, positive value indicating number + * of seconds remaining for a forced system shutdown. This will enable + * the host to schedule for shutdown voluntarily before timeout occurs. + */ +static int64_t fsp_opal_get_dpo_status(int64_t *dpo_timeout) +{ + int64_t timeout = 0; + + if (fsp_dpo_init_tb && fsp_dpo_pending) + timeout = DPO_TIMEOUT - tb_to_secs(mftb() - fsp_dpo_init_tb); + + *dpo_timeout = timeout; + return OPAL_SUCCESS; +} /* Process FSP DPO init message */ static void fsp_process_dpo(struct fsp_msg *msg) @@ -50,6 +71,9 @@ static void fsp_process_dpo(struct fsp_msg *msg) return; } + /* Record the DPO init time */ + fsp_dpo_init_tb = mftb(); + /* Inform the host about DPO */ rc = opal_queue_msg(OPAL_MSG_DPO, NULL, NULL); if (rc) { @@ -90,5 +114,6 @@ static struct fsp_client fsp_dpo_client = { void fsp_dpo_init(void) { fsp_register_client(&fsp_dpo_client, FSP_MCLASS_SERVICE); + opal_register(OPAL_GET_DPO_STATUS, fsp_opal_get_dpo_status, 1); printf(PREFIX "FSP DPO support initialized\n"); } -- cgit v1.1