summaryrefslogtreecommitdiff
path: root/mali_kbase/platform/pixel/pixel_gpu_slc.c
blob: e8aae758bf050b94688dfadbd0be3da53f759a01 (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
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright 2022-2023 Google LLC.
 *
 * Author: Jack Diver <diverj@google.com>
 */

/* Mali core includes */
#include <mali_kbase.h>

/* UAPI includes */
#include <uapi/gpu/arm/midgard/platform/pixel/pixel_gpu_common_slc.h>
/* Back-door mali_pixel include */
#include <uapi/gpu/arm/midgard/platform/pixel/pixel_memory_group_manager.h>

/* Pixel integration includes */
#include "mali_kbase_config_platform.h"
#include "pixel_gpu_slc.h"

#include <uapi/gpu/arm/midgard/platform/pixel/pixel_memory_group_manager.h>

/**
 * enum slc_vote_state - Whether a context is voting for SLC
 */
enum slc_vote_state {
	/** @IDLE: Idle, not voting for SLC */
	IDLE   = 0,
	/** @VOTING: Active, voting for SLC */
	VOTING = 1,
};

/**
 * transition() - Try to transition from one value to another
 *
 * @v:   Value to transition
 * @old: Starting state to transition from
 * @new: Destination state to transition to
 *
 * Return: Whether the transition was successful
 */
static bool transition(int *v, int old, int new)
{
	bool const cond = *v == old;

	if (cond)
		*v = new;

	return cond;
}

/**
 * gpu_pixel_handle_buffer_liveness_update_ioctl() - See gpu_slc_liveness_update
 *
 * @kctx:   The &struct kbase_context corresponding to a user space context which sent the liveness
 *          update
 * @update: See struct kbase_ioctl_buffer_liveness_update
 *
 * Context: Process context. Takes and releases the GPU power domain lock. Expects the caller to
 *          hold the DVFS lock.
 */
int gpu_pixel_handle_buffer_liveness_update_ioctl(struct kbase_context* kctx,
                                                  struct kbase_ioctl_buffer_liveness_update* update)
{
	(void)kctx, (void)update;
	return 0;
}

/**
 * gpu_slc_kctx_init() - Called when a kernel context is created
 *
 * @kctx: The &struct kbase_context that is being initialized
 *
 * This function is called when the GPU driver is initializing a new kernel context. This event is
 * used to set up data structures that will be used to track this context's usage of the SLC.
 *
 * Return: Returns 0 on success, or an error code on failure.
 */
int gpu_slc_kctx_init(struct kbase_context *kctx)
{
	(void)kctx;
	return 0;
}

/**
 * gpu_slc_kctx_term() - Called when a kernel context is terminated
 *
 * @kctx: The &struct kbase_context that is being terminated
 */
void gpu_slc_kctx_term(struct kbase_context *kctx)
{
	struct pixel_platform_data *pd = kctx->platform_data;

	/* Contexts can be terminated without being idled first */
	if (transition(&pd->slc_vote, VOTING, IDLE))
		pixel_mgm_slc_dec_refcount(kctx->kbdev->mgm_dev);
}

/**
 * gpu_slc_kctx_active() - Called when a kernel context is (re)activated
 *
 * @kctx: The &struct kbase_context that is now active
 */
void gpu_slc_kctx_active(struct kbase_context *kctx)
{
	struct pixel_platform_data *pd = kctx->platform_data;

	lockdep_assert_held(&kctx->kbdev->hwaccess_lock);

	if (transition(&pd->slc_vote, IDLE, VOTING))
		pixel_mgm_slc_inc_refcount(kctx->kbdev->mgm_dev);
}

/**
 * gpu_slc_kctx_idle() - Called when a kernel context is idled
 *
 * @kctx: The &struct kbase_context that is now idle
 */
void gpu_slc_kctx_idle(struct kbase_context *kctx)
{
	struct pixel_platform_data *pd = kctx->platform_data;

	lockdep_assert_held(&kctx->kbdev->hwaccess_lock);

	if (transition(&pd->slc_vote, VOTING, IDLE))
		pixel_mgm_slc_dec_refcount(kctx->kbdev->mgm_dev);
}

/**
 * gpu_slc_init - Initialize the SLC context for the GPU
 *
 * @kbdev: The &struct kbase_device for the GPU.
 *
 * Return: On success, returns 0. On failure an error code is returned.
 */
int gpu_slc_init(struct kbase_device *kbdev)
{
	return 0;
}

/**
 * gpu_slc_term() - Terminates the Pixel GPU SLC context.
 *
 * @kbdev: The &struct kbase_device for the GPU.
 */
void gpu_slc_term(struct kbase_device *kbdev)
{
	(void)kbdev;
}