]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/gpu/drm/amd/display/dc/core/dc_surface.c
drm/amd/dc: Add dc display driver (v2)
[mirror_ubuntu-jammy-kernel.git] / drivers / gpu / drm / amd / display / dc / core / dc_surface.c
1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: AMD
23 *
24 */
25
26 /* DC interface (public) */
27 #include "dm_services.h"
28 #include "dc.h"
29
30 /* DC core (private) */
31 #include "core_dc.h"
32 #include "transform.h"
33
34 /*******************************************************************************
35 * Private structures
36 ******************************************************************************/
37 struct surface {
38 struct core_surface protected;
39 enum dc_irq_source irq_source;
40 int ref_count;
41 };
42
43 struct gamma {
44 struct core_gamma protected;
45 int ref_count;
46 };
47
48 #define DC_SURFACE_TO_SURFACE(dc_surface) container_of(dc_surface, struct surface, protected.public)
49 #define CORE_SURFACE_TO_SURFACE(core_surface) container_of(core_surface, struct surface, protected)
50
51 #define DC_GAMMA_TO_GAMMA(dc_gamma) \
52 container_of(dc_gamma, struct gamma, protected.public)
53 #define CORE_GAMMA_TO_GAMMA(core_gamma) \
54 container_of(core_gamma, struct gamma, protected)
55
56 /*******************************************************************************
57 * Private functions
58 ******************************************************************************/
59 static bool construct(struct dc_context *ctx, struct surface *surface)
60 {
61 surface->protected.ctx = ctx;
62 return true;
63 }
64
65 static void destruct(struct surface *surface)
66 {
67
68 }
69
70 /*******************************************************************************
71 * Public functions
72 ******************************************************************************/
73 void enable_surface_flip_reporting(struct dc_surface *dc_surface,
74 uint32_t controller_id)
75 {
76 struct surface *surface = DC_SURFACE_TO_SURFACE(dc_surface);
77 surface->irq_source = controller_id + DC_IRQ_SOURCE_PFLIP1 - 1;
78 /*register_flip_interrupt(surface);*/
79 }
80
81 struct dc_surface *dc_create_surface(const struct dc *dc)
82 {
83 struct core_dc *core_dc = DC_TO_CORE(dc);
84
85 struct surface *surface = dm_alloc(sizeof(*surface));
86
87 if (NULL == surface)
88 goto alloc_fail;
89
90 if (false == construct(core_dc->ctx, surface))
91 goto construct_fail;
92
93 dc_surface_retain(&surface->protected.public);
94
95 return &surface->protected.public;
96
97 construct_fail:
98 dm_free(surface);
99
100 alloc_fail:
101 return NULL;
102 }
103
104 const struct dc_surface_status *dc_surface_get_status(
105 const struct dc_surface *dc_surface)
106 {
107 struct dc_surface_status *surface_status;
108 struct core_surface *core_surface;
109 struct core_dc *core_dc;
110 int i;
111
112 if (dc_surface == NULL)
113 return NULL;
114
115 core_surface = DC_SURFACE_TO_CORE(dc_surface);
116
117 if (core_surface == NULL || core_surface->ctx == NULL)
118 return NULL;
119
120 surface_status = &core_surface->status;
121
122 if (core_surface->ctx == NULL || core_surface->ctx->dc == NULL)
123 return NULL;
124
125 core_dc = DC_TO_CORE(core_surface->ctx->dc);
126
127
128 if (core_dc->current_context == NULL)
129 return NULL;
130
131 for (i = 0; i < core_dc->current_context->res_ctx.pool->pipe_count;
132 i++) {
133 struct pipe_ctx *pipe_ctx =
134 &core_dc->current_context->res_ctx.pipe_ctx[i];
135
136 if (pipe_ctx->surface !=
137 DC_SURFACE_TO_CORE(dc_surface))
138 continue;
139
140 core_dc->hwss.update_pending_status(pipe_ctx);
141 }
142
143 return surface_status;
144 }
145
146 void dc_surface_retain(const struct dc_surface *dc_surface)
147 {
148 struct surface *surface = DC_SURFACE_TO_SURFACE(dc_surface);
149
150 ++surface->ref_count;
151 }
152
153 void dc_surface_release(const struct dc_surface *dc_surface)
154 {
155 struct surface *surface = DC_SURFACE_TO_SURFACE(dc_surface);
156
157 --surface->ref_count;
158
159 if (surface->ref_count == 0) {
160 destruct(surface);
161 dm_free(surface);
162 }
163 }
164
165 static bool construct_gamma(struct gamma *gamma)
166 {
167 return true;
168 }
169
170 static void destruct_gamma(struct gamma *gamma)
171 {
172
173 }
174
175 void dc_gamma_retain(const struct dc_gamma *dc_gamma)
176 {
177 struct gamma *gamma = DC_GAMMA_TO_GAMMA(dc_gamma);
178
179 ++gamma->ref_count;
180 }
181
182 void dc_gamma_release(const struct dc_gamma *dc_gamma)
183 {
184 struct gamma *gamma = DC_GAMMA_TO_GAMMA(dc_gamma);
185 --gamma->ref_count;
186
187 if (gamma->ref_count == 0) {
188 destruct_gamma(gamma);
189 dm_free(gamma);
190 }
191 }
192
193 struct dc_gamma *dc_create_gamma()
194 {
195 struct gamma *gamma = dm_alloc(sizeof(*gamma));
196
197 if (gamma == NULL)
198 goto alloc_fail;
199
200 if (false == construct_gamma(gamma))
201 goto construct_fail;
202
203 dc_gamma_retain(&gamma->protected.public);
204
205 return &gamma->protected.public;
206
207 construct_fail:
208 dm_free(gamma);
209
210 alloc_fail:
211 return NULL;
212 }
213