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