summaryrefslogtreecommitdiff
path: root/mali_kbase/backend/gpu/mali_kbase_pm_ca_devfreq.c
blob: 4bb4c400efe794b2411d6f635ff4288dbc5c55cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 *
 * (C) COPYRIGHT 2017 ARM Limited. All rights reserved.
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU licence.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you can access it online at
 * http://www.gnu.org/licenses/gpl-2.0.html.
 *
 * SPDX-License-Identifier: GPL-2.0
 *
 */

/*
 * A core availability policy implementing core mask selection from devfreq OPPs
 *
 */

#include <mali_kbase.h>
#include <mali_kbase_pm.h>
#include <backend/gpu/mali_kbase_pm_internal.h>
#include <linux/version.h>

void kbase_devfreq_set_core_mask(struct kbase_device *kbdev, u64 core_mask)
{
	struct kbasep_pm_ca_policy_devfreq *data =
				&kbdev->pm.backend.ca_policy_data.devfreq;
	unsigned long flags;

	spin_lock_irqsave(&kbdev->hwaccess_lock, flags);

	data->cores_desired = core_mask;

	/* Disable any cores that are now unwanted */
	data->cores_enabled &= data->cores_desired;

	kbdev->pm.backend.ca_in_transition = true;

	/* If there are no cores to be powered off then power on desired cores
	 */
	if (!(data->cores_used & ~data->cores_desired)) {
		data->cores_enabled = data->cores_desired;
		kbdev->pm.backend.ca_in_transition = false;
	}

	kbase_pm_update_cores_state_nolock(kbdev);

	spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags);

	dev_dbg(kbdev->dev, "Devfreq policy : new core mask=%llX %llX\n",
				data->cores_desired, data->cores_enabled);
}

static void devfreq_init(struct kbase_device *kbdev)
{
	struct kbasep_pm_ca_policy_devfreq *data =
				&kbdev->pm.backend.ca_policy_data.devfreq;

	if (kbdev->current_core_mask) {
		data->cores_enabled = kbdev->current_core_mask;
		data->cores_desired = kbdev->current_core_mask;
	} else {
		data->cores_enabled =
				kbdev->gpu_props.props.raw_props.shader_present;
		data->cores_desired =
				kbdev->gpu_props.props.raw_props.shader_present;
	}
	data->cores_used = 0;
	kbdev->pm.backend.ca_in_transition = false;
}

static void devfreq_term(struct kbase_device *kbdev)
{
}

static u64 devfreq_get_core_mask(struct kbase_device *kbdev)
{
	return kbdev->pm.backend.ca_policy_data.devfreq.cores_enabled;
}

static void devfreq_update_core_status(struct kbase_device *kbdev,
							u64 cores_ready,
							u64 cores_transitioning)
{
	struct kbasep_pm_ca_policy_devfreq *data =
				&kbdev->pm.backend.ca_policy_data.devfreq;

	lockdep_assert_held(&kbdev->hwaccess_lock);

	data->cores_used = cores_ready | cores_transitioning;

	/* If in desired state then clear transition flag */
	if (data->cores_enabled == data->cores_desired)
		kbdev->pm.backend.ca_in_transition = false;

	/* If all undesired cores are now off then power on desired cores.
	 * The direct comparison against cores_enabled limits potential
	 * recursion to one level */
	if (!(data->cores_used & ~data->cores_desired) &&
				data->cores_enabled != data->cores_desired) {
		data->cores_enabled = data->cores_desired;

		kbase_pm_update_cores_state_nolock(kbdev);

		kbdev->pm.backend.ca_in_transition = false;
	}
}

/*
 * The struct kbase_pm_ca_policy structure for the devfreq core availability
 * policy.
 *
 * This is the static structure that defines the devfreq core availability power
 * policy's callback and name.
 */
const struct kbase_pm_ca_policy kbase_pm_ca_devfreq_policy_ops = {
	"devfreq",			/* name */
	devfreq_init,			/* init */
	devfreq_term,			/* term */
	devfreq_get_core_mask,		/* get_core_mask */
	devfreq_update_core_status,	/* update_core_status */
	0u,				/* flags */
	KBASE_PM_CA_POLICY_ID_DEVFREQ,	/* id */
};