aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
blob: 3ec1f363e43e28d7573649a5be9c59059989382f (plain) (blame)
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 * Copyright 2015 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: AMD
 *
 */

/* DC interface (public) */
#include "dm_services.h"
#include "dc.h"

/* DC core (private) */
#include "core_dc.h"
#include "transform.h"

/*******************************************************************************
 * Private structures
 ******************************************************************************/
struct surface {
	struct core_surface protected;
	enum dc_irq_source irq_source;
	int ref_count;
};

struct gamma {
	struct core_gamma protected;
	int ref_count;
};

struct transfer_func {
	struct core_transfer_func protected;
	int ref_count;
};

#define DC_SURFACE_TO_SURFACE(dc_surface) container_of(dc_surface, struct surface, protected.public)
#define CORE_SURFACE_TO_SURFACE(core_surface) container_of(core_surface, struct surface, protected)

#define DC_GAMMA_TO_GAMMA(dc_gamma) \
	container_of(dc_gamma, struct gamma, protected.public)
#define DC_TRANSFER_FUNC_TO_TRANSFER_FUNC(dc_tf) \
	container_of(dc_tf, struct transfer_func, protected.public)
#define CORE_GAMMA_TO_GAMMA(core_gamma) \
	container_of(core_gamma, struct gamma, protected)

/*******************************************************************************
 * Private functions
 ******************************************************************************/
static bool construct(struct dc_context *ctx, struct surface *surface)
{
	surface->protected.ctx = ctx;
	return true;
}

static void destruct(struct surface *surface)
{
	if (surface->protected.public.gamma_correction != NULL)
		dc_gamma_release(surface->protected.public.gamma_correction);
	if (surface->protected.public.in_transfer_func != NULL)
		dc_transfer_func_release(
				surface->protected.public.in_transfer_func);
}

/*******************************************************************************
 * Public functions
 ******************************************************************************/
void enable_surface_flip_reporting(struct dc_surface *dc_surface,
		uint32_t controller_id)
{
	struct surface *surface = DC_SURFACE_TO_SURFACE(dc_surface);
	surface->irq_source = controller_id + DC_IRQ_SOURCE_PFLIP1 - 1;
	/*register_flip_interrupt(surface);*/
}

struct dc_surface *dc_create_surface(const struct dc *dc)
{
	struct core_dc *core_dc = DC_TO_CORE(dc);

	struct surface *surface = dm_alloc(sizeof(*surface));

	if (NULL == surface)
		goto alloc_fail;

	if (false == construct(core_dc->ctx, surface))
		goto construct_fail;

	dc_surface_retain(&surface->protected.public);

	return &surface->protected.public;

construct_fail:
	dm_free(surface);

alloc_fail:
	return NULL;
}

const struct dc_surface_status *dc_surface_get_status(
		const struct dc_surface *dc_surface)
{
	struct dc_surface_status *surface_status;
	struct core_surface *core_surface;
	struct core_dc *core_dc;
	int i;

	if (dc_surface == NULL)
		return NULL;

	core_surface = DC_SURFACE_TO_CORE(dc_surface);

	if (core_surface == NULL || core_surface->ctx == NULL)
		return NULL;

	surface_status = &core_surface->status;

	if (core_surface->ctx == NULL || core_surface->ctx->dc == NULL)
		return NULL;

	core_dc = DC_TO_CORE(core_surface->ctx->dc);


	if (core_dc->current_context == NULL)
		return NULL;

	for (i = 0; i < core_dc->current_context->res_ctx.pool->pipe_count;
			i++) {
		struct pipe_ctx *pipe_ctx =
				&core_dc->current_context->res_ctx.pipe_ctx[i];

		if (pipe_ctx->surface !=
				DC_SURFACE_TO_CORE(dc_surface))
			continue;

		core_dc->hwss.update_pending_status(pipe_ctx);
	}

	return surface_status;
}

void dc_surface_retain(const struct dc_surface *dc_surface)
{
	struct surface *surface = DC_SURFACE_TO_SURFACE(dc_surface);

	++surface->ref_count;
}

void dc_surface_release(const struct dc_surface *dc_surface)
{
	struct surface *surface = DC_SURFACE_TO_SURFACE(dc_surface);

	--surface->ref_count;

	if (surface->ref_count == 0) {
		destruct(surface);
		dm_free(surface);
	}
}

void dc_gamma_retain(const struct dc_gamma *dc_gamma)
{
	struct gamma *gamma = DC_GAMMA_TO_GAMMA(dc_gamma);

	++gamma->ref_count;
}

void dc_gamma_release(const struct dc_gamma *dc_gamma)
{
	struct gamma *gamma = DC_GAMMA_TO_GAMMA(dc_gamma);
	--gamma->ref_count;

	if (gamma->ref_count == 0)
		dm_free(gamma);
}

struct dc_gamma *dc_create_gamma()
{
	struct gamma *gamma = dm_alloc(sizeof(*gamma));

	if (gamma == NULL)
		goto alloc_fail;

	dc_gamma_retain(&gamma->protected.public);

	return &gamma->protected.public;

alloc_fail:
	return NULL;
}

void dc_transfer_func_retain(const struct dc_transfer_func *dc_tf)
{
	struct transfer_func *tf = DC_TRANSFER_FUNC_TO_TRANSFER_FUNC(dc_tf);

	++tf->ref_count;
}

void dc_transfer_func_release(const struct dc_transfer_func *dc_tf)
{
	struct transfer_func *tf = DC_TRANSFER_FUNC_TO_TRANSFER_FUNC(dc_tf);
	--tf->ref_count;

	if (tf->ref_count == 0)
		dm_free(tf);
}

struct dc_transfer_func *dc_create_transfer_func()
{
	struct transfer_func *tf = dm_alloc(sizeof(*tf));

	if (tf == NULL)
		goto alloc_fail;

	dc_transfer_func_retain(&tf->protected.public);

	return &tf->protected.public;

alloc_fail:
	return NULL;
}