1/* SPDX-License-Identifier: MIT */ 2/* 3 * Copyright �� 2019 Intel Corporation 4 */ 5 6#ifndef INTEL_GT_PM_H 7#define INTEL_GT_PM_H 8 9#include <linux/types.h> 10 11#include "intel_gt_types.h" 12#include "intel_wakeref.h" 13 14static inline bool intel_gt_pm_is_awake(const struct intel_gt *gt) 15{ 16 return intel_wakeref_is_active(>->wakeref); 17} 18 19static inline void intel_gt_pm_get(struct intel_gt *gt) 20{ 21 intel_wakeref_get(>->wakeref); 22} 23 24static inline void __intel_gt_pm_get(struct intel_gt *gt) 25{ 26 __intel_wakeref_get(>->wakeref); 27} 28 29static inline bool intel_gt_pm_get_if_awake(struct intel_gt *gt) 30{ 31 return intel_wakeref_get_if_active(>->wakeref); 32} 33 34static inline void intel_gt_pm_might_get(struct intel_gt *gt) 35{ 36 intel_wakeref_might_get(>->wakeref); 37} 38 39static inline void intel_gt_pm_put(struct intel_gt *gt) 40{ 41 intel_wakeref_put(>->wakeref); 42} 43 44static inline void intel_gt_pm_put_async(struct intel_gt *gt) 45{ 46 intel_wakeref_put_async(>->wakeref); 47} 48 49static inline void intel_gt_pm_might_put(struct intel_gt *gt) 50{ 51 intel_wakeref_might_put(>->wakeref); 52} 53 54#define with_intel_gt_pm(gt, tmp) \ 55 for (tmp = 1, intel_gt_pm_get(gt); tmp; \ 56 intel_gt_pm_put(gt), tmp = 0) 57 58/** 59 * with_intel_gt_pm_if_awake - if GT is PM awake, get a reference to prevent 60 * it to sleep, run some code and then asynchrously put the reference 61 * away. 62 * 63 * @gt: pointer to the gt 64 * @wf: pointer to a temporary wakeref. 65 */ 66#define with_intel_gt_pm_if_awake(gt, wf) \ 67 for (wf = intel_gt_pm_get_if_awake(gt); wf; intel_gt_pm_put_async(gt), wf = 0) 68 69static inline int intel_gt_pm_wait_for_idle(struct intel_gt *gt) 70{ 71 return intel_wakeref_wait_for_idle(>->wakeref); 72} 73 74void intel_gt_pm_init_early(struct intel_gt *gt); 75void intel_gt_pm_init(struct intel_gt *gt); 76void intel_gt_pm_fini(struct intel_gt *gt); 77 78void intel_gt_suspend_prepare(struct intel_gt *gt); 79void intel_gt_suspend_late(struct intel_gt *gt); 80int intel_gt_resume(struct intel_gt *gt); 81 82void intel_gt_runtime_suspend(struct intel_gt *gt); 83int intel_gt_runtime_resume(struct intel_gt *gt); 84 85ktime_t intel_gt_get_awake_time(const struct intel_gt *gt); 86 87static inline bool is_mock_gt(const struct intel_gt *gt) 88{ 89 return I915_SELFTEST_ONLY(gt->awake == -ENODEV); 90} 91 92#endif /* INTEL_GT_PM_H */ 93