linux/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
<<
>>
Prefs
   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_types.h"
  32#include "transform.h"
  33#include "dpp.h"
  34
  35/*******************************************************************************
  36 * Private functions
  37 ******************************************************************************/
  38static void construct(struct dc_context *ctx, struct dc_plane_state *plane_state)
  39{
  40        plane_state->ctx = ctx;
  41
  42        plane_state->gamma_correction = dc_create_gamma();
  43        plane_state->gamma_correction->is_identity = true;
  44
  45        plane_state->in_transfer_func = dc_create_transfer_func();
  46        plane_state->in_transfer_func->type = TF_TYPE_BYPASS;
  47        plane_state->in_transfer_func->ctx = ctx;
  48}
  49
  50static void destruct(struct dc_plane_state *plane_state)
  51{
  52        if (plane_state->gamma_correction != NULL) {
  53                dc_gamma_release(&plane_state->gamma_correction);
  54        }
  55        if (plane_state->in_transfer_func != NULL) {
  56                dc_transfer_func_release(
  57                                plane_state->in_transfer_func);
  58                plane_state->in_transfer_func = NULL;
  59        }
  60}
  61
  62/*******************************************************************************
  63 * Public functions
  64 ******************************************************************************/
  65void enable_surface_flip_reporting(struct dc_plane_state *plane_state,
  66                uint32_t controller_id)
  67{
  68        plane_state->irq_source = controller_id + DC_IRQ_SOURCE_PFLIP1 - 1;
  69        /*register_flip_interrupt(surface);*/
  70}
  71
  72struct dc_plane_state *dc_create_plane_state(struct dc *dc)
  73{
  74        struct dc *core_dc = dc;
  75
  76        struct dc_plane_state *plane_state = kvzalloc(sizeof(*plane_state),
  77                                                      GFP_KERNEL);
  78
  79        if (NULL == plane_state)
  80                return NULL;
  81
  82        kref_init(&plane_state->refcount);
  83        construct(core_dc->ctx, plane_state);
  84
  85        return plane_state;
  86}
  87
  88/**
  89 *****************************************************************************
  90 *  Function: dc_plane_get_status
  91 *
  92 *  @brief
  93 *     Looks up the pipe context of plane_state and updates the pending status
  94 *     of the pipe context. Then returns plane_state->status
  95 *
  96 *  @param [in] plane_state: pointer to the plane_state to get the status of
  97 *****************************************************************************
  98 */
  99const struct dc_plane_status *dc_plane_get_status(
 100                const struct dc_plane_state *plane_state)
 101{
 102        const struct dc_plane_status *plane_status;
 103        struct dc  *core_dc;
 104        int i;
 105
 106        if (!plane_state ||
 107                !plane_state->ctx ||
 108                !plane_state->ctx->dc) {
 109                ASSERT(0);
 110                return NULL; /* remove this if above assert never hit */
 111        }
 112
 113        plane_status = &plane_state->status;
 114        core_dc = plane_state->ctx->dc;
 115
 116        if (core_dc->current_state == NULL)
 117                return NULL;
 118
 119        for (i = 0; i < core_dc->res_pool->pipe_count; i++) {
 120                struct pipe_ctx *pipe_ctx =
 121                                &core_dc->current_state->res_ctx.pipe_ctx[i];
 122
 123                if (pipe_ctx->plane_state != plane_state)
 124                        continue;
 125
 126                core_dc->hwss.update_pending_status(pipe_ctx);
 127        }
 128
 129        return plane_status;
 130}
 131
 132void dc_plane_state_retain(struct dc_plane_state *plane_state)
 133{
 134        kref_get(&plane_state->refcount);
 135}
 136
 137static void dc_plane_state_free(struct kref *kref)
 138{
 139        struct dc_plane_state *plane_state = container_of(kref, struct dc_plane_state, refcount);
 140        destruct(plane_state);
 141        kvfree(plane_state);
 142}
 143
 144void dc_plane_state_release(struct dc_plane_state *plane_state)
 145{
 146        kref_put(&plane_state->refcount, dc_plane_state_free);
 147}
 148
 149void dc_gamma_retain(struct dc_gamma *gamma)
 150{
 151        kref_get(&gamma->refcount);
 152}
 153
 154static void dc_gamma_free(struct kref *kref)
 155{
 156        struct dc_gamma *gamma = container_of(kref, struct dc_gamma, refcount);
 157        kvfree(gamma);
 158}
 159
 160void dc_gamma_release(struct dc_gamma **gamma)
 161{
 162        kref_put(&(*gamma)->refcount, dc_gamma_free);
 163        *gamma = NULL;
 164}
 165
 166struct dc_gamma *dc_create_gamma(void)
 167{
 168        struct dc_gamma *gamma = kvzalloc(sizeof(*gamma), GFP_KERNEL);
 169
 170        if (gamma == NULL)
 171                goto alloc_fail;
 172
 173        kref_init(&gamma->refcount);
 174        return gamma;
 175
 176alloc_fail:
 177        return NULL;
 178}
 179
 180void dc_transfer_func_retain(struct dc_transfer_func *tf)
 181{
 182        kref_get(&tf->refcount);
 183}
 184
 185static void dc_transfer_func_free(struct kref *kref)
 186{
 187        struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount);
 188        kvfree(tf);
 189}
 190
 191void dc_transfer_func_release(struct dc_transfer_func *tf)
 192{
 193        kref_put(&tf->refcount, dc_transfer_func_free);
 194}
 195
 196struct dc_transfer_func *dc_create_transfer_func(void)
 197{
 198        struct dc_transfer_func *tf = kvzalloc(sizeof(*tf), GFP_KERNEL);
 199
 200        if (tf == NULL)
 201                goto alloc_fail;
 202
 203        kref_init(&tf->refcount);
 204
 205        return tf;
 206
 207alloc_fail:
 208        return NULL;
 209}
 210
 211
 212