f6a97c7c6b899ffa3a06bbf63911a90a4112fb5b
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / t6xx / kbase / src / common / mali_kbase_pm_ca.h
1 /*
2  *
3  * (C) COPYRIGHT ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18 /**
19  * @file mali_kbase_pm_ca.h
20  * Base kernel core availability APIs
21  */
22
23 #ifndef _KBASE_PM_CA_H_
24 #define _KBASE_PM_CA_H_
25
26 typedef enum kbase_pm_ca_policy_id {
27         KBASE_PM_CA_POLICY_ID_FIXED = 1,
28         KBASE_PM_CA_POLICY_ID_RANDOM
29 } kbase_pm_ca_policy_id;
30
31 typedef u32 kbase_pm_ca_policy_flags;
32
33 /** Core availability policy structure.
34  *
35  * Each core availability policy exposes a (static) instance of this structure which contains function pointers to the
36  * policy's methods.
37  */
38 typedef struct kbase_pm_ca_policy {
39         /** The name of this policy */
40         char *name;
41
42         /** Function called when the policy is selected
43          *
44          * This should initialize the kbdev->pm.ca_policy_data structure. It should not attempt
45          * to make any changes to hardware state.
46          *
47          * It is undefined what state the cores are in when the function is called.
48          *
49          * @param kbdev     The kbase device structure for the device (must be a valid pointer)
50          */
51         void (*init) (struct kbase_device *kbdev);
52
53         /** Function called when the policy is unselected.
54          *
55          * @param kbdev     The kbase device structure for the device (must be a valid pointer)
56          */
57         void (*term) (struct kbase_device *kbdev);
58
59         /** Function called to get the current shader core availability mask
60          *
61          * When a change in core availability is occuring, the policy must set kbdev->pm.ca_in_transition
62          * to MALI_TRUE. This is to indicate that reporting changes in power state cannot be optimized out,
63          * even if kbdev->pm.desired_shader_state remains unchanged. This must be done by any functions
64          * internal to the Core Availability Policy that change the return value of
65          * kbase_pm_ca_policy::get_core_mask.
66          *
67          * @param kbdev     The kbase device structure for the device (must be a valid pointer)
68          *
69          * @return     The current core availability mask */
70         u64 (*get_core_mask) (struct kbase_device *kbdev);
71
72         /** Function called to update the current core status
73          *
74          * If none of the cores in core group 0 are ready or transitioning, then the policy must
75          * ensure that the next call to get_core_mask does not return 0 for all cores in core group
76          * 0. It is an error to disable core group 0 through the core availability policy.
77          *
78          * When a change in core availability has finished, the policy must set kbdev->pm.ca_in_transition
79          * to MALI_FALSE. This is to indicate that changes in power state can once again be optimized out
80          * when kbdev->pm.desired_shader_state is unchanged.
81          *
82          * @param kbdev                   The kbase device structure for the device (must be a valid pointer)
83          * @param cores_ready             The mask of cores currently powered and ready to run jobs
84          * @param cores_transitioning     The mask of cores currently transitioning power state */
85         void (*update_core_status) (struct kbase_device *kbdev, u64 cores_ready, u64 cores_transitioning);
86
87         /** Field indicating flags for this policy */
88         kbase_pm_ca_policy_flags flags;
89
90         /** Field indicating an ID for this policy. This is not necessarily the
91          * same as its index in the list returned by kbase_pm_list_policies().
92          * It is used purely for debugging. */
93         kbase_pm_ca_policy_id id;
94 } kbase_pm_ca_policy;
95
96 /** Initialize core availability framework
97  *
98  * Must be called before calling any other core availability function
99  *
100  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
101  *
102  * @return MALI_ERROR_NONE if the core availability framework was successfully initialized.
103  */
104 mali_error kbase_pm_ca_init(struct kbase_device *kbdev);
105
106 /** Terminate core availability framework
107  *
108  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
109  */
110 void kbase_pm_ca_term(struct kbase_device *kbdev);
111
112 /** Return mask of currently available shaders cores
113  * Calls into the core availability policy
114  *
115  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
116  *
117  * @return          The bit mask of available cores
118  */
119 u64 kbase_pm_ca_get_core_mask(struct kbase_device *kbdev);
120
121 /** Update core availability policy with current core power status
122  * Calls into the core availability policy
123  *
124  * @param kbdev                The kbase device structure for the device (must be a valid pointer)
125  * @param cores_ready          The bit mask of cores ready for job submission
126  * @param cores_transitioning  The bit mask of cores that are transitioning power state
127  */
128 void kbase_pm_ca_update_core_status(struct kbase_device *kbdev, u64 cores_ready, u64 cores_transitioning);
129
130 /** Enable override for instrumentation
131  *
132  * This overrides the output of the core availability policy, ensuring that all cores are available
133  *
134  * @param kbdev                The kbase device structure for the device (must be a valid pointer)
135  */
136 void kbase_pm_ca_instr_enable(struct kbase_device *kbdev);
137
138 /** Disable override for instrumentation
139  *
140  * This disables any previously enabled override, and resumes normal policy functionality
141  *
142  * @param kbdev                The kbase device structure for the device (must be a valid pointer)
143  */
144 void kbase_pm_ca_instr_disable(struct kbase_device *kbdev);
145
146 /** Get the current policy.
147  * Returns the policy that is currently active.
148  *
149  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
150  *
151  * @return The current policy
152  */
153 const kbase_pm_ca_policy *kbase_pm_ca_get_policy(struct kbase_device *kbdev);
154
155 /** Change the policy to the one specified.
156  *
157  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
158  * @param policy    The policy to change to (valid pointer returned from @ref kbase_pm_ca_list_policies)
159  */
160 void kbase_pm_ca_set_policy(struct kbase_device *kbdev, const kbase_pm_ca_policy *policy);
161
162 /** Retrieve a static list of the available policies.
163  * @param[out]  policies    An array pointer to take the list of policies. This may be NULL.
164  *                          The contents of this array must not be modified.
165  *
166  * @return The number of policies
167  */
168 int kbase_pm_ca_list_policies(const kbase_pm_ca_policy * const **policies);
169
170 #endif                          /* _KBASE_PM_CA_H_ */