root/drivers/gpu/drm/amd/display/dc/core/dc_surface.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. construct
  2. destruct
  3. enable_surface_flip_reporting
  4. dc_create_plane_state
  5. dc_plane_get_status
  6. dc_plane_state_retain
  7. dc_plane_state_free
  8. dc_plane_state_release
  9. dc_gamma_retain
  10. dc_gamma_free
  11. dc_gamma_release
  12. dc_create_gamma
  13. dc_transfer_func_retain
  14. dc_transfer_func_free
  15. dc_transfer_func_release
  16. dc_create_transfer_func
  17. dc_3dlut_func_free
  18. dc_create_3dlut_func
  19. dc_3dlut_func_release
  20. dc_3dlut_func_retain

   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 #include <linux/mm.h>
  27 
  28 /* DC interface (public) */
  29 #include "dm_services.h"
  30 #include "dc.h"
  31 
  32 /* DC core (private) */
  33 #include "core_types.h"
  34 #include "transform.h"
  35 #include "dpp.h"
  36 
  37 /*******************************************************************************
  38  * Private functions
  39  ******************************************************************************/
  40 static void construct(struct dc_context *ctx, struct dc_plane_state *plane_state)
  41 {
  42         plane_state->ctx = ctx;
  43 
  44         plane_state->gamma_correction = dc_create_gamma();
  45         if (plane_state->gamma_correction != NULL)
  46                 plane_state->gamma_correction->is_identity = true;
  47 
  48         plane_state->in_transfer_func = dc_create_transfer_func();
  49         if (plane_state->in_transfer_func != NULL) {
  50                 plane_state->in_transfer_func->type = TF_TYPE_BYPASS;
  51                 plane_state->in_transfer_func->ctx = ctx;
  52         }
  53 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
  54         plane_state->in_shaper_func = dc_create_transfer_func();
  55         if (plane_state->in_shaper_func != NULL) {
  56                 plane_state->in_shaper_func->type = TF_TYPE_BYPASS;
  57                 plane_state->in_shaper_func->ctx = ctx;
  58         }
  59 
  60         plane_state->lut3d_func = dc_create_3dlut_func();
  61         if (plane_state->lut3d_func != NULL) {
  62                 plane_state->lut3d_func->ctx = ctx;
  63         }
  64         plane_state->blend_tf = dc_create_transfer_func();
  65         if (plane_state->blend_tf != NULL) {
  66                 plane_state->blend_tf->type = TF_TYPE_BYPASS;
  67                 plane_state->blend_tf->ctx = ctx;
  68         }
  69 
  70 #endif
  71 }
  72 
  73 static void destruct(struct dc_plane_state *plane_state)
  74 {
  75         if (plane_state->gamma_correction != NULL) {
  76                 dc_gamma_release(&plane_state->gamma_correction);
  77         }
  78         if (plane_state->in_transfer_func != NULL) {
  79                 dc_transfer_func_release(
  80                                 plane_state->in_transfer_func);
  81                 plane_state->in_transfer_func = NULL;
  82         }
  83 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
  84         if (plane_state->in_shaper_func != NULL) {
  85                 dc_transfer_func_release(
  86                                 plane_state->in_shaper_func);
  87                 plane_state->in_shaper_func = NULL;
  88         }
  89         if (plane_state->lut3d_func != NULL) {
  90                 dc_3dlut_func_release(
  91                                 plane_state->lut3d_func);
  92                 plane_state->lut3d_func = NULL;
  93         }
  94         if (plane_state->blend_tf != NULL) {
  95                 dc_transfer_func_release(
  96                                 plane_state->blend_tf);
  97                 plane_state->blend_tf = NULL;
  98         }
  99 
 100 #endif
 101 }
 102 
 103 /*******************************************************************************
 104  * Public functions
 105  ******************************************************************************/
 106 void enable_surface_flip_reporting(struct dc_plane_state *plane_state,
 107                 uint32_t controller_id)
 108 {
 109         plane_state->irq_source = controller_id + DC_IRQ_SOURCE_PFLIP1 - 1;
 110         /*register_flip_interrupt(surface);*/
 111 }
 112 
 113 struct dc_plane_state *dc_create_plane_state(struct dc *dc)
 114 {
 115         struct dc *core_dc = dc;
 116 
 117         struct dc_plane_state *plane_state = kvzalloc(sizeof(*plane_state),
 118                                                       GFP_KERNEL);
 119 
 120         if (NULL == plane_state)
 121                 return NULL;
 122 
 123         kref_init(&plane_state->refcount);
 124         construct(core_dc->ctx, plane_state);
 125 
 126         return plane_state;
 127 }
 128 
 129 /**
 130  *****************************************************************************
 131  *  Function: dc_plane_get_status
 132  *
 133  *  @brief
 134  *     Looks up the pipe context of plane_state and updates the pending status
 135  *     of the pipe context. Then returns plane_state->status
 136  *
 137  *  @param [in] plane_state: pointer to the plane_state to get the status of
 138  *****************************************************************************
 139  */
 140 const struct dc_plane_status *dc_plane_get_status(
 141                 const struct dc_plane_state *plane_state)
 142 {
 143         const struct dc_plane_status *plane_status;
 144         struct dc  *core_dc;
 145         int i;
 146 
 147         if (!plane_state ||
 148                 !plane_state->ctx ||
 149                 !plane_state->ctx->dc) {
 150                 ASSERT(0);
 151                 return NULL; /* remove this if above assert never hit */
 152         }
 153 
 154         plane_status = &plane_state->status;
 155         core_dc = plane_state->ctx->dc;
 156 
 157         if (core_dc->current_state == NULL)
 158                 return NULL;
 159 
 160         /* Find the current plane state and set its pending bit to false */
 161         for (i = 0; i < core_dc->res_pool->pipe_count; i++) {
 162                 struct pipe_ctx *pipe_ctx =
 163                                 &core_dc->current_state->res_ctx.pipe_ctx[i];
 164 
 165                 if (pipe_ctx->plane_state != plane_state)
 166                         continue;
 167 
 168                 pipe_ctx->plane_state->status.is_flip_pending = false;
 169 
 170                 break;
 171         }
 172 
 173         for (i = 0; i < core_dc->res_pool->pipe_count; i++) {
 174                 struct pipe_ctx *pipe_ctx =
 175                                 &core_dc->current_state->res_ctx.pipe_ctx[i];
 176 
 177                 if (pipe_ctx->plane_state != plane_state)
 178                         continue;
 179 
 180                 core_dc->hwss.update_pending_status(pipe_ctx);
 181         }
 182 
 183         return plane_status;
 184 }
 185 
 186 void dc_plane_state_retain(struct dc_plane_state *plane_state)
 187 {
 188         kref_get(&plane_state->refcount);
 189 }
 190 
 191 static void dc_plane_state_free(struct kref *kref)
 192 {
 193         struct dc_plane_state *plane_state = container_of(kref, struct dc_plane_state, refcount);
 194         destruct(plane_state);
 195         kvfree(plane_state);
 196 }
 197 
 198 void dc_plane_state_release(struct dc_plane_state *plane_state)
 199 {
 200         kref_put(&plane_state->refcount, dc_plane_state_free);
 201 }
 202 
 203 void dc_gamma_retain(struct dc_gamma *gamma)
 204 {
 205         kref_get(&gamma->refcount);
 206 }
 207 
 208 static void dc_gamma_free(struct kref *kref)
 209 {
 210         struct dc_gamma *gamma = container_of(kref, struct dc_gamma, refcount);
 211         kvfree(gamma);
 212 }
 213 
 214 void dc_gamma_release(struct dc_gamma **gamma)
 215 {
 216         kref_put(&(*gamma)->refcount, dc_gamma_free);
 217         *gamma = NULL;
 218 }
 219 
 220 struct dc_gamma *dc_create_gamma(void)
 221 {
 222         struct dc_gamma *gamma = kvzalloc(sizeof(*gamma), GFP_KERNEL);
 223 
 224         if (gamma == NULL)
 225                 goto alloc_fail;
 226 
 227         kref_init(&gamma->refcount);
 228         return gamma;
 229 
 230 alloc_fail:
 231         return NULL;
 232 }
 233 
 234 void dc_transfer_func_retain(struct dc_transfer_func *tf)
 235 {
 236         kref_get(&tf->refcount);
 237 }
 238 
 239 static void dc_transfer_func_free(struct kref *kref)
 240 {
 241         struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount);
 242         kvfree(tf);
 243 }
 244 
 245 void dc_transfer_func_release(struct dc_transfer_func *tf)
 246 {
 247         kref_put(&tf->refcount, dc_transfer_func_free);
 248 }
 249 
 250 struct dc_transfer_func *dc_create_transfer_func(void)
 251 {
 252         struct dc_transfer_func *tf = kvzalloc(sizeof(*tf), GFP_KERNEL);
 253 
 254         if (tf == NULL)
 255                 goto alloc_fail;
 256 
 257         kref_init(&tf->refcount);
 258 
 259         return tf;
 260 
 261 alloc_fail:
 262         return NULL;
 263 }
 264 
 265 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
 266 static void dc_3dlut_func_free(struct kref *kref)
 267 {
 268         struct dc_3dlut *lut = container_of(kref, struct dc_3dlut, refcount);
 269 
 270         kvfree(lut);
 271 }
 272 
 273 struct dc_3dlut *dc_create_3dlut_func(void)
 274 {
 275         struct dc_3dlut *lut = kvzalloc(sizeof(*lut), GFP_KERNEL);
 276 
 277         if (lut == NULL)
 278                 goto alloc_fail;
 279 
 280         kref_init(&lut->refcount);
 281         lut->state.raw = 0;
 282 
 283         return lut;
 284 
 285 alloc_fail:
 286         return NULL;
 287 
 288 }
 289 
 290 void dc_3dlut_func_release(struct dc_3dlut *lut)
 291 {
 292         kref_put(&lut->refcount, dc_3dlut_func_free);
 293 }
 294 
 295 void dc_3dlut_func_retain(struct dc_3dlut *lut)
 296 {
 297         kref_get(&lut->refcount);
 298 }
 299 #endif
 300 
 301 

/* [<][>][^][v][top][bottom][index][help] */