hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/gpu/drm/rockchip/ebc-dev/bufmanage/buf_manage.c
....@@ -28,10 +28,8 @@
2828 struct buf_list_s *dsp_buf_list; /* dispplay buffer list. */
2929 int dsp_buf_list_status;
3030 struct ebc_buf_s *osd_buf;
31
- struct buf_list_s *osd_buf_list; /* dispplay buffer list. */
32
- struct mutex osd_buf_lock;
33
- struct mutex dsp_buf_lock;
34
- struct mutex ebc_buf_lock;
31
+
32
+ struct mutex dsp_lock;
3533 };
3634
3735 static struct buf_info_s ebc_buf_info;
....@@ -56,83 +54,84 @@
5654 return BUF_SUCCESS;
5755 }
5856
59
-static void do_dsp_buf_list(struct ebc_buf_s *dsp_buf)
57
+int ebc_remove_from_dsp_buf_list(struct ebc_buf_s *remove_buf)
6058 {
61
- struct ebc_buf_s *temp_buf;
62
- int temp_pos;
63
-
64
- if (ebc_buf_info.dsp_buf_list->nb_elt > 0) {
65
- temp_pos = ebc_buf_info.dsp_buf_list->nb_elt;
66
- while (temp_pos) {
67
- temp_pos--;
68
- temp_buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.dsp_buf_list, temp_pos);
69
- if (temp_buf->needpic) {
70
- continue;
71
- } else {
72
- buf_list_remove(ebc_buf_info.dsp_buf_list, temp_pos);
73
- ebc_buf_release(temp_buf);
74
- }
75
- }
76
- }
77
-}
78
-
79
-int ebc_add_to_dsp_buf_list(struct ebc_buf_s *dsp_buf)
80
-{
81
- mutex_lock(&ebc_buf_info.dsp_buf_lock);
59
+ mutex_lock(&ebc_buf_info.dsp_lock);
8260 if (ebc_buf_info.dsp_buf_list) {
83
- do_dsp_buf_list(dsp_buf);
61
+ int pos;
8462
85
- if (-1 == buf_list_add(ebc_buf_info.dsp_buf_list, (int *)dsp_buf, -1)) {
86
- ebc_buf_release(dsp_buf);
87
- mutex_unlock(&ebc_buf_info.dsp_buf_lock);
88
- return BUF_ERROR;
89
- }
90
-
91
- if (dsp_buf->status != buf_osd)
92
- dsp_buf->status = buf_dsp;
63
+ pos = buf_list_get_pos(ebc_buf_info.dsp_buf_list, (int *)remove_buf);
64
+ buf_list_remove(ebc_buf_info.dsp_buf_list, pos);
9365 }
94
- mutex_unlock(&ebc_buf_info.dsp_buf_lock);
66
+ mutex_unlock(&ebc_buf_info.dsp_lock);
9567
9668 return BUF_SUCCESS;
9769 }
9870
99
-int ebc_add_to_osd_buf_list(struct ebc_buf_s *dsp_buf)
71
+int ebc_add_to_dsp_buf_list(struct ebc_buf_s *dsp_buf)
10072 {
101
- int ret = BUF_SUCCESS;
73
+ struct ebc_buf_s *temp_buf;
74
+ int temp_pos;
75
+ int is_full_mode = 0;
10276
103
- mutex_lock(&ebc_buf_info.osd_buf_lock);
104
- if (ebc_buf_info.osd_buf_list) {
105
- if (-1 == buf_list_add(ebc_buf_info.osd_buf_list, (int *)dsp_buf, -1)) {
106
- ebc_buf_release(dsp_buf);
107
- ret = BUF_ERROR;
77
+ mutex_lock(&ebc_buf_info.dsp_lock);
78
+ if (ebc_buf_info.dsp_buf_list) {
79
+ switch (dsp_buf->buf_mode) {
80
+ case EPD_DU:
81
+ case EPD_SUSPEND:
82
+ case EPD_RESUME:
83
+ case EPD_POWER_OFF:
84
+ case EPD_OVERLAY:
85
+ case EPD_RESET:
86
+ break;
87
+
88
+ default:
89
+ if (ebc_buf_info.dsp_buf_list->nb_elt > 1) {
90
+ temp_pos = ebc_buf_info.dsp_buf_list->nb_elt;
91
+ while (--temp_pos) {
92
+ temp_buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.dsp_buf_list, temp_pos);
93
+ if ((temp_buf->buf_mode != EPD_FULL_GC16) &&
94
+ (temp_buf->buf_mode != EPD_FULL_GL16) &&
95
+ (temp_buf->buf_mode != EPD_FULL_GLR16) &&
96
+ (temp_buf->buf_mode != EPD_FULL_GLD16) &&
97
+ (temp_buf->buf_mode != EPD_FULL_GCC16) &&
98
+ (temp_buf->buf_mode != EPD_OVERLAY) &&
99
+ (temp_buf->buf_mode != EPD_DU) &&
100
+ (temp_buf->buf_mode != EPD_SUSPEND) &&
101
+ (temp_buf->buf_mode != EPD_RESUME) &&
102
+ (temp_buf->buf_mode != EPD_POWER_OFF)) {
103
+ buf_list_remove(ebc_buf_info.dsp_buf_list, temp_pos);
104
+ ebc_buf_release(temp_buf);
105
+ } else if ((1 == is_full_mode) &&
106
+ (temp_buf->buf_mode != EPD_DU) &&
107
+ (temp_buf->buf_mode != EPD_OVERLAY) &&
108
+ (temp_buf->buf_mode != EPD_SUSPEND) &&
109
+ (temp_buf->buf_mode != EPD_RESUME) &&
110
+ (temp_buf->buf_mode != EPD_POWER_OFF)) {
111
+ buf_list_remove(ebc_buf_info.dsp_buf_list, temp_pos);
112
+ ebc_buf_release(temp_buf);
113
+ } else {
114
+ is_full_mode = 1;
115
+ }
116
+ }
117
+ }
118
+ break;
119
+ }
120
+
121
+ dsp_buf->status = buf_dsp;
122
+ if (-1 == buf_list_add(ebc_buf_info.dsp_buf_list, (int *)dsp_buf, -1)) {
123
+ mutex_unlock(&ebc_buf_info.dsp_lock);
124
+ return BUF_ERROR;
108125 }
109126 }
110
- mutex_unlock(&ebc_buf_info.osd_buf_lock);
111
- return ret;
112
-}
127
+ mutex_unlock(&ebc_buf_info.dsp_lock);
113128
114
-struct ebc_buf_s *ebc_osd_buf_get(void)
115
-{
116
- struct ebc_buf_s *buf = NULL;
117
-
118
- mutex_lock(&ebc_buf_info.osd_buf_lock);
119
- if (ebc_buf_info.osd_buf_list && (ebc_buf_info.osd_buf_list->nb_elt > 0)) {
120
- buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.osd_buf_list, 0);
121
- buf_list_remove(ebc_buf_info.osd_buf_list, 0);
122
- }
123
- mutex_unlock(&ebc_buf_info.osd_buf_lock);
124
-
125
- return buf;
129
+ return BUF_SUCCESS;
126130 }
127131
128132 int ebc_get_dsp_list_enum_num(void)
129133 {
130134 return ebc_buf_info.dsp_buf_list->nb_elt;
131
-}
132
-
133
-int ebc_get_osd_list_enum_num(void)
134
-{
135
- return ebc_buf_info.osd_buf_list->nb_elt;
136135 }
137136
138137 struct ebc_buf_s *ebc_find_buf_by_phy_addr(unsigned long phy_addr)
....@@ -156,17 +155,15 @@
156155 {
157156 struct ebc_buf_s *buf = NULL;
158157
159
- mutex_lock(&ebc_buf_info.dsp_buf_lock);
160
- if (ebc_buf_info.dsp_buf_list && (ebc_buf_info.dsp_buf_list->nb_elt > 0)) {
158
+ mutex_lock(&ebc_buf_info.dsp_lock);
159
+ if (ebc_buf_info.dsp_buf_list && (ebc_buf_info.dsp_buf_list->nb_elt > 0))
161160 buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.dsp_buf_list, 0);
162
- buf_list_remove(ebc_buf_info.dsp_buf_list, 0);
163
- }
164
- mutex_unlock(&ebc_buf_info.dsp_buf_lock);
161
+ mutex_unlock(&ebc_buf_info.dsp_lock);
165162
166163 return buf;
167164 }
168165
169
-struct ebc_buf_s *ebc_empty_osd_buf_get(void)
166
+struct ebc_buf_s *ebc_osd_buf_get(void)
170167 {
171168 if (ebc_buf_info.osd_buf)
172169 return ebc_buf_info.osd_buf;
....@@ -188,13 +185,12 @@
188185 return temp_buf;
189186 }
190187
191
-struct ebc_buf_s *ebc_empty_buf_get(const char *tid_name)
188
+struct ebc_buf_s *ebc_empty_buf_get(void)
192189 {
193
- struct ebc_buf_s *temp_buf = NULL;
190
+ struct ebc_buf_s *temp_buf;
194191 int temp_pos;
195192
196
- mutex_lock(&ebc_buf_info.ebc_buf_lock);
197
- while (ebc_buf_info.buf_list) {
193
+ if (ebc_buf_info.buf_list) {
198194 temp_pos = 0;
199195
200196 while (temp_pos < ebc_buf_info.buf_list->nb_elt) {
....@@ -202,23 +198,23 @@
202198 if (temp_buf) {
203199 if (temp_buf->status == buf_idle) {
204200 temp_buf->status = buf_user;
205
- memcpy(temp_buf->tid_name, tid_name, TASK_COMM_LEN - 1); //store user thread name
206
- goto OUT;
201
+ memcpy(temp_buf->tid_name, current->comm, TASK_COMM_LEN); //store user thread name
202
+ return temp_buf;
207203 }
208204 // one tid only can get one buf at one time
209
- else if ((temp_buf->status == buf_user) && (!strncmp(temp_buf->tid_name, tid_name, TASK_COMM_LEN - 1))) {
210
- printk("[%s]: one tid only can get one buf at one time\n", tid_name);
211
- goto OUT;
205
+ else if ((temp_buf->status == buf_user) && (!strncmp(temp_buf->tid_name, current->comm, TASK_COMM_LEN - 7))) {
206
+ return temp_buf;
212207 }
213208 }
214209 }
215210 ebc_buf_info.use_buf_is_empty = 1;
211
+
216212 wait_event_interruptible(ebc_buf_wq, ebc_buf_info.use_buf_is_empty != 1);
213
+
214
+ return ebc_empty_buf_get();
217215 }
218216
219
-OUT:
220
- mutex_unlock(&ebc_buf_info.ebc_buf_lock);
221
- return temp_buf;
217
+ return NULL;
222218 }
223219
224220 unsigned long ebc_phy_buf_base_get(void)
....@@ -229,23 +225,6 @@
229225 char *ebc_virt_buf_base_get(void)
230226 {
231227 return ebc_buf_info.virt_mem_base;
232
-}
233
-
234
-int ebc_buf_state_show(char *buf)
235
-{
236
- int i;
237
- int ret = 0;
238
- struct ebc_buf_s *temp_buf;
239
-
240
- ret += sprintf(buf, "dsp_buf num = %d\n", ebc_buf_info.dsp_buf_list->nb_elt);
241
- if (ebc_buf_info.buf_list) {
242
- for (i = 0; i < ebc_buf_info.buf_list->nb_elt; i++) {
243
- temp_buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.buf_list, i);
244
- ret += sprintf(buf + ret, "ebc_buf[%d]: s = %d, m = %d, tid = %s\n", i, temp_buf->status, temp_buf->buf_mode, temp_buf->tid_name);
245
- }
246
- }
247
-
248
- return ret;
249228 }
250229
251230 int ebc_buf_uninit(void)
....@@ -281,21 +260,14 @@
281260 if (NULL == mem_start)
282261 return BUF_ERROR;
283262
284
- mutex_init(&ebc_buf_info.dsp_buf_lock);
285
- mutex_init(&ebc_buf_info.ebc_buf_lock);
286
- mutex_init(&ebc_buf_info.osd_buf_lock);
263
+ mutex_init(&ebc_buf_info.dsp_lock);
287264
288265 if (buf_list_init(&ebc_buf_info.buf_list, BUF_LIST_MAX_NUMBER))
289266 return BUF_ERROR;
290267
291268 if (buf_list_init(&ebc_buf_info.dsp_buf_list, BUF_LIST_MAX_NUMBER)) {
292269 res = BUF_ERROR;
293
- goto dsp_list_err;
294
- }
295
-
296
- if (buf_list_init(&ebc_buf_info.osd_buf_list, BUF_LIST_MAX_NUMBER)) {
297
- res = BUF_ERROR;
298
- goto osd_list_err;
270
+ goto buf_list_err;
299271 }
300272
301273 ebc_buf_info.buf_total_num = 0;
....@@ -345,13 +317,10 @@
345317 }
346318
347319 return BUF_SUCCESS;
348
-
349320 exit:
350321 ebc_buf_uninit();
351
- buf_list_uninit(ebc_buf_info.osd_buf_list);
352
-osd_list_err:
353322 buf_list_uninit(ebc_buf_info.dsp_buf_list);
354
-dsp_list_err:
323
+buf_list_err:
355324 buf_list_uninit(ebc_buf_info.buf_list);
356325
357326 return res;