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