aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/samsung/mali/common/mali_cluster.c
blob: f0fb2b6137b12350d9eddb2dda455ff16097e73f (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * Copyright (C) 2011-2012 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.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "mali_kernel_common.h"
#include "mali_cluster.h"
#include "mali_osk.h"
#include "mali_group.h"
#include "mali_l2_cache.h"
#include "mali_scheduler.h"

static struct mali_cluster *mali_global_clusters[MALI_MAX_NUMBER_OF_CLUSTERS] = { NULL, NULL, NULL };
static u32 mali_global_num_clusters = 0;

/**
 * The structure represents a render cluster
 * A render cluster is defined by all the cores that share the same Mali L2 cache
 */
struct mali_cluster
{
	struct mali_l2_cache_core *l2;
	u32 number_of_groups;
	struct mali_group* groups[MALI_MAX_NUMBER_OF_GROUPS_PER_CLUSTER];
	u32 last_invalidated_id;
	mali_bool power_is_enabled;
};

struct mali_cluster *mali_cluster_create(struct mali_l2_cache_core *l2_cache)
{
	struct mali_cluster *cluster = NULL;

	if (mali_global_num_clusters >= MALI_MAX_NUMBER_OF_CLUSTERS)
	{
		MALI_PRINT_ERROR(("Mali cluster: Too many cluster objects created\n"));
		return NULL;
	}

	cluster = _mali_osk_malloc(sizeof(struct mali_cluster));
	if (NULL != cluster)
	{
		_mali_osk_memset(cluster, 0, sizeof(struct mali_cluster));
		cluster->l2 = l2_cache; /* This cluster now owns this L2 cache object */
		cluster->last_invalidated_id = 0;
		cluster->power_is_enabled = MALI_TRUE;

		mali_global_clusters[mali_global_num_clusters] = cluster;
		mali_global_num_clusters++;

		return cluster;
	}

	return NULL;
}

void mali_cluster_power_is_enabled_set(struct mali_cluster * cluster, mali_bool power_is_enabled)
{
	cluster->power_is_enabled = power_is_enabled;
}

mali_bool mali_cluster_power_is_enabled_get(struct mali_cluster * cluster)
{
	return cluster->power_is_enabled;
}


void mali_cluster_add_group(struct mali_cluster *cluster, struct mali_group *group)
{
	MALI_DEBUG_ASSERT_POINTER(cluster);

	if (cluster->number_of_groups < MALI_MAX_NUMBER_OF_GROUPS_PER_CLUSTER)
	{
		/* This cluster now owns the group object */
		cluster->groups[cluster->number_of_groups] = group;
		cluster->number_of_groups++;
	}
}

void mali_cluster_delete(struct mali_cluster *cluster)
{
	u32 i;

	MALI_DEBUG_ASSERT_POINTER(cluster);

	/* Free all the resources we own */
	for (i = 0; i < cluster->number_of_groups; i++)
	{
		mali_group_delete(cluster->groups[i]);
	}

	if (NULL != cluster->l2)
	{
		mali_l2_cache_delete(cluster->l2);
	}

	for (i = 0; i < mali_global_num_clusters; i++)
	{
		if (mali_global_clusters[i] == cluster)
		{
			mali_global_clusters[i] = NULL;
			mali_global_num_clusters--;
			break;
		}
	}

	_mali_osk_free(cluster);
}

void mali_cluster_reset(struct mali_cluster *cluster)
{
	u32 i;

	MALI_DEBUG_ASSERT_POINTER(cluster);

	/* Free all the resources we own */
	for (i = 0; i < cluster->number_of_groups; i++)
	{
		struct mali_group *group = cluster->groups[i];

		mali_group_reset(group);
	}

	if (NULL != cluster->l2)
	{
		mali_l2_cache_reset(cluster->l2);
	}
}

struct mali_l2_cache_core* mali_cluster_get_l2_cache_core(struct mali_cluster *cluster)
{
	MALI_DEBUG_ASSERT_POINTER(cluster);
	return cluster->l2;
}

struct mali_group *mali_cluster_get_group(struct mali_cluster *cluster, u32 index)
{
	MALI_DEBUG_ASSERT_POINTER(cluster);

	if (index <  cluster->number_of_groups)
	{
		return cluster->groups[index];
	}

	return NULL;
}

struct mali_cluster *mali_cluster_get_global_cluster(u32 index)
{
	if (MALI_MAX_NUMBER_OF_CLUSTERS > index)
	{
		return mali_global_clusters[index];
	}

	return NULL;
}

u32 mali_cluster_get_glob_num_clusters(void)
{
	return mali_global_num_clusters;
}

mali_bool mali_cluster_l2_cache_invalidate_all(struct mali_cluster *cluster, u32 id)
{
	MALI_DEBUG_ASSERT_POINTER(cluster);

	if (NULL != cluster->l2)
	{
		/* If the last cache invalidation was done by a job with a higher id we
		 * don't have to flush. Since user space will store jobs w/ their
		 * corresponding memory in sequence (first job #0, then job #1, ...),
		 * we don't have to flush for job n-1 if job n has already invalidated
		 * the cache since we know for sure that job n-1's memory was already
		 * written when job n was started. */
		if (((s32)id) <= ((s32)cluster->last_invalidated_id))
		{
			return MALI_FALSE;
		}
		else
		{
			cluster->last_invalidated_id = mali_scheduler_get_new_id();
		}

		mali_l2_cache_invalidate_all(cluster->l2);
	}
	return MALI_TRUE;
}

void mali_cluster_l2_cache_invalidate_all_force(struct mali_cluster *cluster)
{
	MALI_DEBUG_ASSERT_POINTER(cluster);

	if (NULL != cluster->l2)
	{
		cluster->last_invalidated_id = mali_scheduler_get_new_id();
		mali_l2_cache_invalidate_all(cluster->l2);
	}
}

void mali_cluster_invalidate_pages(u32 *pages, u32 num_pages)
{
	u32 i;

	for (i = 0; i < mali_global_num_clusters; i++)
	{
		/*additional check for cluster*/
		if (MALI_TRUE == mali_l2_cache_lock_power_state(mali_global_clusters[i]->l2))
		{
			mali_l2_cache_invalidate_pages(mali_global_clusters[i]->l2, pages, num_pages);
		}
		mali_l2_cache_unlock_power_state(mali_global_clusters[i]->l2);
		/*check for failed power locking???*/
	}
}