/** Function to handle the @ref KBASE_PM_EVENT_SYSTEM_RESUME message for the always_on power policy.
 *
 * This function is called when a @ref KBASE_PM_EVENT_SYSTEM_RESUME message is received. It instructs the GPU to turn on all 
 * the cores.
 *
 * @param kbdev     The kbase device structure for the device
 */
static void always_on_resume(kbase_device *kbdev)
{
	u64 cores;

	/* Inform the system that the transition has started */
	kbase_pm_power_transitioning(kbdev);

	/* Turn the clock on */
	kbase_pm_clock_on(kbdev);
	/* Enable interrupts */
	kbase_pm_enable_interrupts(kbdev);

	/* Turn the cores on */
	cores = kbase_pm_get_present_cores(kbdev, KBASE_PM_CORE_SHADER);
	kbase_pm_invoke_power_up(kbdev, KBASE_PM_CORE_SHADER, cores);

	cores = kbase_pm_get_present_cores(kbdev, KBASE_PM_CORE_TILER);
	kbase_pm_invoke_power_up(kbdev, KBASE_PM_CORE_TILER, cores);

	kbase_pm_check_transitions(kbdev);

	kbdev->pm.policy_data.always_on.state = KBASEP_PM_ALWAYS_ON_STATE_POWERING_UP;

	/* Ensure that the OS is informed even if we didn't do anything */
	always_on_state_changed(kbdev);
}
/** The event callback function for the always_on power policy.
 *
 * This function is called to handle the events for the power policy. It calls the relevant handler function depending 
 * on the type of the event.
 *
 * @param kbdev     The kbase device structure for the device
 * @param event     The event that should be processed
 */
static void always_on_event(kbase_device *kbdev, kbase_pm_event event)
{
	kbasep_pm_policy_always_on *data = &kbdev->pm.policy_data.always_on;

	switch(event)
	{
	case KBASE_PM_EVENT_SYSTEM_SUSPEND:
		always_on_suspend(kbdev);
		break;
	case KBASE_PM_EVENT_POLICY_INIT: /* Init is the same as resume for this policy */
	case KBASE_PM_EVENT_SYSTEM_RESUME:
		always_on_resume(kbdev);
		break;
	case KBASE_PM_EVENT_GPU_STATE_CHANGED:
		always_on_state_changed(kbdev);
		break;
	case KBASE_PM_EVENT_POLICY_CHANGE:
		if (data->state == KBASEP_PM_ALWAYS_ON_STATE_POWERED_UP ||
		    data->state == KBASEP_PM_ALWAYS_ON_STATE_POWERED_DOWN)
		{
			kbase_pm_change_policy(kbdev);
		}
		else
		{
			data->state = KBASEP_PM_ALWAYS_ON_STATE_CHANGING_POLICY;
		}
		break;
	case KBASE_PM_EVENT_GPU_ACTIVE:
	case KBASE_PM_EVENT_GPU_IDLE:
	case KBASE_PM_EVENT_CHANGE_GPU_STATE:
		/* Not used - the GPU is always kept on */
		break;
	default:
		/* Unrecognised event - this should never happen */
		OSK_ASSERT(0);
	}
}
/** The event callback function for the always_on power policy.
 *
 * This function is called to handle the events for the power policy. It calls the relevant handler function depending
 * on the type of the event.
 *
 * @param kbdev     The kbase device structure for the device
 * @param event     The event that should be processed
 */
static void always_on_event(kbase_device *kbdev, kbase_pm_event event)
{
	kbasep_pm_policy_always_on *data = &kbdev->pm.policy_data.always_on;

	switch (event) {
	case KBASE_PM_EVENT_SYSTEM_SUSPEND:
		always_on_suspend(kbdev);
		break;
	case KBASE_PM_EVENT_POLICY_INIT:	/* Init is the same as resume for this policy */
	case KBASE_PM_EVENT_SYSTEM_RESUME:
		always_on_resume(kbdev);
		break;
	case KBASE_PM_EVENT_GPU_STATE_CHANGED:
		always_on_state_changed(kbdev);
		break;
	case KBASE_PM_EVENT_POLICY_CHANGE:
		if (data->state == KBASEP_PM_ALWAYS_ON_STATE_POWERED_UP || data->state == KBASEP_PM_ALWAYS_ON_STATE_POWERED_DOWN)
			kbase_pm_change_policy(kbdev);
		else
			data->state = KBASEP_PM_ALWAYS_ON_STATE_CHANGING_POLICY;
		break;
	case KBASE_PM_EVENT_GPU_ACTIVE:
	case KBASE_PM_EVENT_GPU_IDLE:
		break;
	case KBASE_PM_EVENT_CHANGE_GPU_STATE:
		/*
		 * Note that the GPU is always kept on, however we still may
		 * be required to update anyone waiting for power up events.
		 */
		kbase_pm_check_transitions(kbdev);
		break;
	default:
		/* Unrecognised event - this should never happen */
		KBASE_DEBUG_ASSERT(0);
	}
}