Home | History | Annotate | Line # | Download | only in core
      1 /*	$NetBSD: amdgpu_dc_sink.c,v 1.2 2021/12/18 23:45:02 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2012-15 Advanced Micro Devices, Inc.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included in
     14  * all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  * OTHER DEALINGS IN THE SOFTWARE.
     23  *
     24  * Authors: AMD
     25  *
     26  */
     27 
     28 #include <sys/cdefs.h>
     29 __KERNEL_RCSID(0, "$NetBSD: amdgpu_dc_sink.c,v 1.2 2021/12/18 23:45:02 riastradh Exp $");
     30 
     31 #include <linux/slab.h>
     32 
     33 #include "dm_services.h"
     34 #include "dm_helpers.h"
     35 #include "core_types.h"
     36 
     37 /*******************************************************************************
     38  * Private functions
     39  ******************************************************************************/
     40 
     41 static void dc_sink_destruct(struct dc_sink *sink)
     42 {
     43 	if (sink->dc_container_id) {
     44 		kfree(sink->dc_container_id);
     45 		sink->dc_container_id = NULL;
     46 	}
     47 }
     48 
     49 static bool dc_sink_construct(struct dc_sink *sink, const struct dc_sink_init_data *init_params)
     50 {
     51 
     52 	struct dc_link *link = init_params->link;
     53 
     54 	if (!link)
     55 		return false;
     56 
     57 	sink->sink_signal = init_params->sink_signal;
     58 	sink->link = link;
     59 	sink->ctx = link->ctx;
     60 	sink->dongle_max_pix_clk = init_params->dongle_max_pix_clk;
     61 	sink->converter_disable_audio = init_params->converter_disable_audio;
     62 	sink->dc_container_id = NULL;
     63 	sink->sink_id = init_params->link->ctx->dc_sink_id_count;
     64 	// increment dc_sink_id_count because we don't want two sinks with same ID
     65 	// unless they are actually the same
     66 	init_params->link->ctx->dc_sink_id_count++;
     67 
     68 	return true;
     69 }
     70 
     71 /*******************************************************************************
     72  * Public functions
     73  ******************************************************************************/
     74 
     75 void dc_sink_retain(struct dc_sink *sink)
     76 {
     77 	kref_get(&sink->refcount);
     78 }
     79 
     80 static void dc_sink_free(struct kref *kref)
     81 {
     82 	struct dc_sink *sink = container_of(kref, struct dc_sink, refcount);
     83 	dc_sink_destruct(sink);
     84 	kfree(sink);
     85 }
     86 
     87 void dc_sink_release(struct dc_sink *sink)
     88 {
     89 	kref_put(&sink->refcount, dc_sink_free);
     90 }
     91 
     92 struct dc_sink *dc_sink_create(const struct dc_sink_init_data *init_params)
     93 {
     94 	struct dc_sink *sink = kzalloc(sizeof(*sink), GFP_KERNEL);
     95 
     96 	if (NULL == sink)
     97 		goto alloc_fail;
     98 
     99 	if (false == dc_sink_construct(sink, init_params))
    100 		goto construct_fail;
    101 
    102 	kref_init(&sink->refcount);
    103 
    104 	return sink;
    105 
    106 construct_fail:
    107 	kfree(sink);
    108 
    109 alloc_fail:
    110 	return NULL;
    111 }
    112 
    113 /*******************************************************************************
    114  * Protected functions - visible only inside of DC (not visible in DM)
    115  ******************************************************************************/
    116