hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
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,106 +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_drop_one_dsp_buf(void)
80
-{
81
- struct ebc_buf_s *temp_buf;
82
- int temp_pos;
83
-
84
- mutex_lock(&ebc_buf_info.dsp_buf_lock);
59
+ mutex_lock(&ebc_buf_info.dsp_lock);
8560 if (ebc_buf_info.dsp_buf_list) {
86
- if (ebc_buf_info.dsp_buf_list->nb_elt > 0) {
87
- temp_pos = ebc_buf_info.dsp_buf_list->nb_elt - 1;
88
- temp_buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.dsp_buf_list, temp_pos);
89
- if (temp_buf->needpic == 2) {
90
- buf_list_remove(ebc_buf_info.dsp_buf_list, temp_pos);
91
- ebc_buf_release(temp_buf);
92
- mutex_unlock(&ebc_buf_info.dsp_buf_lock);
93
- return BUF_SUCCESS;
94
- }
95
- }
61
+ int pos;
62
+
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);
9665 }
97
- mutex_unlock(&ebc_buf_info.dsp_buf_lock);
98
-
99
- return BUF_ERROR;
100
-}
101
-
102
-int ebc_add_to_dsp_buf_list(struct ebc_buf_s *dsp_buf)
103
-{
104
- mutex_lock(&ebc_buf_info.dsp_buf_lock);
105
- if (ebc_buf_info.dsp_buf_list) {
106
- do_dsp_buf_list(dsp_buf);
107
-
108
- if (-1 == buf_list_add(ebc_buf_info.dsp_buf_list, (int *)dsp_buf, -1)) {
109
- ebc_buf_release(dsp_buf);
110
- mutex_unlock(&ebc_buf_info.dsp_buf_lock);
111
- return BUF_ERROR;
112
- }
113
-
114
- if (dsp_buf->status != buf_osd)
115
- dsp_buf->status = buf_dsp;
116
- }
117
- mutex_unlock(&ebc_buf_info.dsp_buf_lock);
66
+ mutex_unlock(&ebc_buf_info.dsp_lock);
11867
11968 return BUF_SUCCESS;
12069 }
12170
122
-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)
12372 {
124
- int ret = BUF_SUCCESS;
73
+ struct ebc_buf_s *temp_buf;
74
+ int temp_pos;
75
+ int is_full_mode = 0;
12576
126
- mutex_lock(&ebc_buf_info.osd_buf_lock);
127
- if (ebc_buf_info.osd_buf_list) {
128
- if (-1 == buf_list_add(ebc_buf_info.osd_buf_list, (int *)dsp_buf, -1)) {
129
- ebc_buf_release(dsp_buf);
130
- 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;
131125 }
132126 }
133
- mutex_unlock(&ebc_buf_info.osd_buf_lock);
134
- return ret;
135
-}
127
+ mutex_unlock(&ebc_buf_info.dsp_lock);
136128
137
-struct ebc_buf_s *ebc_osd_buf_get(void)
138
-{
139
- struct ebc_buf_s *buf = NULL;
140
-
141
- mutex_lock(&ebc_buf_info.osd_buf_lock);
142
- if (ebc_buf_info.osd_buf_list && (ebc_buf_info.osd_buf_list->nb_elt > 0)) {
143
- buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.osd_buf_list, 0);
144
- buf_list_remove(ebc_buf_info.osd_buf_list, 0);
145
- }
146
- mutex_unlock(&ebc_buf_info.osd_buf_lock);
147
-
148
- return buf;
129
+ return BUF_SUCCESS;
149130 }
150131
151132 int ebc_get_dsp_list_enum_num(void)
152133 {
153134 return ebc_buf_info.dsp_buf_list->nb_elt;
154
-}
155
-
156
-int ebc_get_osd_list_enum_num(void)
157
-{
158
- return ebc_buf_info.osd_buf_list->nb_elt;
159135 }
160136
161137 struct ebc_buf_s *ebc_find_buf_by_phy_addr(unsigned long phy_addr)
....@@ -179,17 +155,15 @@
179155 {
180156 struct ebc_buf_s *buf = NULL;
181157
182
- mutex_lock(&ebc_buf_info.dsp_buf_lock);
183
- 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))
184160 buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.dsp_buf_list, 0);
185
- buf_list_remove(ebc_buf_info.dsp_buf_list, 0);
186
- }
187
- mutex_unlock(&ebc_buf_info.dsp_buf_lock);
161
+ mutex_unlock(&ebc_buf_info.dsp_lock);
188162
189163 return buf;
190164 }
191165
192
-struct ebc_buf_s *ebc_empty_osd_buf_get(void)
166
+struct ebc_buf_s *ebc_osd_buf_get(void)
193167 {
194168 if (ebc_buf_info.osd_buf)
195169 return ebc_buf_info.osd_buf;
....@@ -211,13 +185,12 @@
211185 return temp_buf;
212186 }
213187
214
-struct ebc_buf_s *ebc_empty_buf_get(const char *tid_name)
188
+struct ebc_buf_s *ebc_empty_buf_get(void)
215189 {
216
- struct ebc_buf_s *temp_buf = NULL;
190
+ struct ebc_buf_s *temp_buf;
217191 int temp_pos;
218192
219
- mutex_lock(&ebc_buf_info.ebc_buf_lock);
220
- while (ebc_buf_info.buf_list) {
193
+ if (ebc_buf_info.buf_list) {
221194 temp_pos = 0;
222195
223196 while (temp_pos < ebc_buf_info.buf_list->nb_elt) {
....@@ -225,23 +198,23 @@
225198 if (temp_buf) {
226199 if (temp_buf->status == buf_idle) {
227200 temp_buf->status = buf_user;
228
- memcpy(temp_buf->tid_name, tid_name, TASK_COMM_LEN - 1); //store user thread name
229
- goto OUT;
201
+ memcpy(temp_buf->tid_name, current->comm, TASK_COMM_LEN); //store user thread name
202
+ return temp_buf;
230203 }
231204 // one tid only can get one buf at one time
232
- else if ((temp_buf->status == buf_user) && (!strncmp(temp_buf->tid_name, tid_name, TASK_COMM_LEN - 1))) {
233
- printk("[%s]: one tid only can get one buf at one time\n", tid_name);
234
- 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;
235207 }
236208 }
237209 }
238210 ebc_buf_info.use_buf_is_empty = 1;
211
+
239212 wait_event_interruptible(ebc_buf_wq, ebc_buf_info.use_buf_is_empty != 1);
213
+
214
+ return ebc_empty_buf_get();
240215 }
241216
242
-OUT:
243
- mutex_unlock(&ebc_buf_info.ebc_buf_lock);
244
- return temp_buf;
217
+ return NULL;
245218 }
246219
247220 unsigned long ebc_phy_buf_base_get(void)
....@@ -252,23 +225,6 @@
252225 char *ebc_virt_buf_base_get(void)
253226 {
254227 return ebc_buf_info.virt_mem_base;
255
-}
256
-
257
-int ebc_buf_state_show(char *buf)
258
-{
259
- int i;
260
- int ret = 0;
261
- struct ebc_buf_s *temp_buf;
262
-
263
- ret += sprintf(buf, "dsp_buf num = %d\n", ebc_buf_info.dsp_buf_list->nb_elt);
264
- if (ebc_buf_info.buf_list) {
265
- for (i = 0; i < ebc_buf_info.buf_list->nb_elt; i++) {
266
- temp_buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.buf_list, i);
267
- 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);
268
- }
269
- }
270
-
271
- return ret;
272228 }
273229
274230 int ebc_buf_uninit(void)
....@@ -304,21 +260,14 @@
304260 if (NULL == mem_start)
305261 return BUF_ERROR;
306262
307
- mutex_init(&ebc_buf_info.dsp_buf_lock);
308
- mutex_init(&ebc_buf_info.ebc_buf_lock);
309
- mutex_init(&ebc_buf_info.osd_buf_lock);
263
+ mutex_init(&ebc_buf_info.dsp_lock);
310264
311265 if (buf_list_init(&ebc_buf_info.buf_list, BUF_LIST_MAX_NUMBER))
312266 return BUF_ERROR;
313267
314268 if (buf_list_init(&ebc_buf_info.dsp_buf_list, BUF_LIST_MAX_NUMBER)) {
315269 res = BUF_ERROR;
316
- goto dsp_list_err;
317
- }
318
-
319
- if (buf_list_init(&ebc_buf_info.osd_buf_list, BUF_LIST_MAX_NUMBER)) {
320
- res = BUF_ERROR;
321
- goto osd_list_err;
270
+ goto buf_list_err;
322271 }
323272
324273 ebc_buf_info.buf_total_num = 0;
....@@ -368,13 +317,10 @@
368317 }
369318
370319 return BUF_SUCCESS;
371
-
372320 exit:
373321 ebc_buf_uninit();
374
- buf_list_uninit(ebc_buf_info.osd_buf_list);
375
-osd_list_err:
376322 buf_list_uninit(ebc_buf_info.dsp_buf_list);
377
-dsp_list_err:
323
+buf_list_err:
378324 buf_list_uninit(ebc_buf_info.buf_list);
379325
380326 return res;