summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/dal/topology/tm_resource.h
blob: d7384e3fd8b6b39d3d95d8f6a011f3d13eaf57ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * Copyright 2012-15 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: AMD
 *
 */

#ifndef __DAL_TM_RESOURCE_H__
#define __DAL_TM_RESOURCE_H__

/* Generic structure to hold interface to
 * HW resource + TM proprietary info + resource-specific info */
struct tm_resource_flags {
	uint8_t resource_active:1;
	uint8_t display_path_resource:1;
	uint8_t mst_resource:1;
	uint8_t multi_path:1;
};

struct tm_resource;

/* These functions perform operations SPECIFIC for a type of resource.  */
struct tm_resource_funcs {
	void (*destroy)(struct tm_resource **resource);
	struct tm_resource * (*clone)(struct tm_resource *resource);
	void (*release_hw)(struct tm_resource *resource);
	const struct graphics_object_id (*get_grph_id)(
		const struct tm_resource *resource);
	uint32_t (*get_priority)(const struct tm_resource *resource);
	void (*set_multi_path)(
		struct tm_resource *resource,
		bool is_multi_path);
};

/* Reference count functions - these operations IDENTICAL for all types of
 * resources. */
void tm_res_ref_counter_increment(struct tm_resource *resource);
void tm_res_ref_counter_decrement(struct tm_resource *resource);
uint32_t tm_res_ref_counter_get(const struct tm_resource *resource);
void tm_res_ref_counter_reset(struct tm_resource *resource);
/**** end of reference count functions ****/


struct tm_resource_private;

struct tm_resource {
	const struct tm_resource_funcs *funcs;

	/* private data of tm_resource */
	struct tm_resource_private *res_private;

	struct tm_resource_flags flags;
};


struct tm_resource_connector_info {
	struct tm_resource resource;
	struct ddc_service *ddc_service;
	struct connector *connector;
};

struct tm_resource_encoder_info {
	struct tm_resource resource;
	struct encoder *encoder;
	uint32_t paired_encoder_index;
};

struct tm_resource_controller_info {
	struct tm_resource resource;
	struct controller *controller;
	enum tm_power_gate_state power_gating_state;
};

struct tm_resource_clock_source_info {
	struct tm_resource resource;
	struct clock_source *clock_source;
	enum clock_sharing_group clk_sharing_group;
};

struct tm_resource_engine_info {
	struct tm_resource resource;
	enum tm_engine_priority priority;
	struct graphics_object_id id;
};

struct tm_resource_audio_info {
	struct tm_resource resource;
	struct audio *audio;
};

struct tm_resource *dal_tm_resource_encoder_create(struct encoder *enc);
struct tm_resource *dal_tm_resource_audio_create(struct audio *audio);
struct tm_resource *dal_tm_resource_engine_create(struct graphics_object_id id);
struct tm_resource *dal_tm_resource_clock_source_create(
	struct clock_source *cs);
struct tm_resource *dal_tm_resource_connector_create(struct connector *conn);
struct tm_resource *dal_tm_resource_controller_create(struct controller *cntl);

#define GRPH_ID(resource) ((resource)->funcs->get_grph_id((resource)))

#define TO_CONNECTOR_INFO(tm_resource)\
	(container_of((tm_resource),\
		struct tm_resource_connector_info, resource))

#define TO_CONNECTOR(tm_resource) (TO_CONNECTOR_INFO(tm_resource)->connector)

#define TO_CONTROLLER_INFO(tm_resource)\
	(container_of((tm_resource),\
		struct tm_resource_controller_info, resource))

#define TO_CONTROLLER(tm_resource) (TO_CONTROLLER_INFO(tm_resource)->controller)

#define TO_ENCODER_INFO(tm_resource)\
	(container_of((tm_resource),\
		struct tm_resource_encoder_info, resource))

#define TO_ENCODER(tm_resource) (TO_ENCODER_INFO(tm_resource)->encoder)

#define TO_CLOCK_SOURCE_INFO(tm_resource)\
	(container_of((tm_resource),\
		struct tm_resource_clock_source_info, resource))
#define TO_CLOCK_SOURCE(tm_resource)\
	(TO_CLOCK_SOURCE_INFO(tm_resource)->clock_source)

#define TO_ENGINE_INFO(tm_resource)\
	(container_of((tm_resource),\
		struct tm_resource_engine_info, resource))

#define TO_AUDIO_INFO(tm_resource)\
	(container_of((tm_resource),\
		struct tm_resource_audio_info, resource))
#define TO_AUDIO(tm_resource) (TO_AUDIO_INFO(tm_resource)->audio)


#define TM_RES_REF_CNT_INCREMENT(resource) \
	(tm_res_ref_counter_increment(resource))
#define TM_RES_REF_CNT_DECREMENT(resource) \
	(tm_res_ref_counter_decrement(resource))
#define TM_RES_REF_CNT_GET(resource) \
	(tm_res_ref_counter_get(resource))
#define TM_RES_REF_CNT_RESET(resource) \
	(tm_res_ref_counter_reset(resource))

#endif