1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include "mdp5_kms.h"
18
19
20
21
22
23
24
25
26
27
28static int lm_right_pair[] = { 1, -1, 5, -1, -1, -1 };
29
30static int get_right_pair_idx(struct mdp5_kms *mdp5_kms, int lm)
31{
32 int i;
33 int pair_lm;
34
35 pair_lm = lm_right_pair[lm];
36 if (pair_lm < 0)
37 return -EINVAL;
38
39 for (i = 0; i < mdp5_kms->num_hwmixers; i++) {
40 struct mdp5_hw_mixer *mixer = mdp5_kms->hwmixers[i];
41
42 if (mixer->lm == pair_lm)
43 return mixer->idx;
44 }
45
46 return -1;
47}
48
49int mdp5_mixer_assign(struct drm_atomic_state *s, struct drm_crtc *crtc,
50 uint32_t caps, struct mdp5_hw_mixer **mixer,
51 struct mdp5_hw_mixer **r_mixer)
52{
53 struct msm_drm_private *priv = s->dev->dev_private;
54 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms));
55 struct mdp5_global_state *global_state = mdp5_get_global_state(s);
56 struct mdp5_hw_mixer_state *new_state;
57 int i;
58
59 if (IS_ERR(global_state))
60 return PTR_ERR(global_state);
61
62 new_state = &global_state->hwmixer;
63
64 for (i = 0; i < mdp5_kms->num_hwmixers; i++) {
65 struct mdp5_hw_mixer *cur = mdp5_kms->hwmixers[i];
66
67
68
69
70
71
72
73
74 if (new_state->hwmixer_to_crtc[cur->idx] &&
75 new_state->hwmixer_to_crtc[cur->idx] != crtc)
76 continue;
77
78
79 if (caps & ~cur->caps)
80 continue;
81
82 if (r_mixer) {
83 int pair_idx;
84
85 pair_idx = get_right_pair_idx(mdp5_kms, cur->lm);
86 if (pair_idx < 0)
87 return -EINVAL;
88
89 if (new_state->hwmixer_to_crtc[pair_idx])
90 continue;
91
92 *r_mixer = mdp5_kms->hwmixers[pair_idx];
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 if (!(*mixer) || cur->caps & MDP_LM_CAP_PAIR)
109 *mixer = cur;
110 }
111
112 if (!(*mixer))
113 return -ENOMEM;
114
115 if (r_mixer && !(*r_mixer))
116 return -ENOMEM;
117
118 DBG("assigning Layer Mixer %d to crtc %s", (*mixer)->lm, crtc->name);
119
120 new_state->hwmixer_to_crtc[(*mixer)->idx] = crtc;
121 if (r_mixer) {
122 DBG("assigning Right Layer Mixer %d to crtc %s", (*r_mixer)->lm,
123 crtc->name);
124 new_state->hwmixer_to_crtc[(*r_mixer)->idx] = crtc;
125 }
126
127 return 0;
128}
129
130void mdp5_mixer_release(struct drm_atomic_state *s, struct mdp5_hw_mixer *mixer)
131{
132 struct mdp5_global_state *global_state = mdp5_get_global_state(s);
133 struct mdp5_hw_mixer_state *new_state = &global_state->hwmixer;
134
135 if (!mixer)
136 return;
137
138 if (WARN_ON(!new_state->hwmixer_to_crtc[mixer->idx]))
139 return;
140
141 DBG("%s: release from crtc %s", mixer->name,
142 new_state->hwmixer_to_crtc[mixer->idx]->name);
143
144 new_state->hwmixer_to_crtc[mixer->idx] = NULL;
145}
146
147void mdp5_mixer_destroy(struct mdp5_hw_mixer *mixer)
148{
149 kfree(mixer);
150}
151
152static const char * const mixer_names[] = {
153 "LM0", "LM1", "LM2", "LM3", "LM4", "LM5",
154};
155
156struct mdp5_hw_mixer *mdp5_mixer_init(const struct mdp5_lm_instance *lm)
157{
158 struct mdp5_hw_mixer *mixer;
159
160 mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
161 if (!mixer)
162 return ERR_PTR(-ENOMEM);
163
164 mixer->name = mixer_names[lm->id];
165 mixer->lm = lm->id;
166 mixer->caps = lm->caps;
167 mixer->pp = lm->pp;
168 mixer->dspp = lm->dspp;
169 mixer->flush_mask = mdp_ctl_flush_mask_lm(lm->id);
170
171 return mixer;
172}
173