1111#include "lima_device.h"
1212#include "lima_gp.h"
1313#include "lima_regs.h"
14+ #include "lima_gem.h"
15+ #include "lima_vm.h"
1416
1517#define gp_write (reg , data ) writel(data, ip->iomem + reg)
1618#define gp_read (reg ) readl(ip->iomem + reg)
@@ -20,6 +22,7 @@ static irqreturn_t lima_gp_irq_handler(int irq, void *data)
2022 struct lima_ip * ip = data ;
2123 struct lima_device * dev = ip -> dev ;
2224 struct lima_sched_pipe * pipe = dev -> pipe + lima_pipe_gp ;
25+ struct lima_sched_task * task = pipe -> current_task ;
2326 u32 state = gp_read (LIMA_GP_INT_STAT );
2427 u32 status = gp_read (LIMA_GP_STATUS );
2528 bool done = false;
@@ -29,8 +32,16 @@ static irqreturn_t lima_gp_irq_handler(int irq, void *data)
2932 return IRQ_NONE ;
3033
3134 if (state & LIMA_GP_IRQ_MASK_ERROR ) {
32- dev_err (dev -> dev , "gp error irq state=%x status=%x\n" ,
33- state , status );
35+ if ((state & LIMA_GP_IRQ_MASK_ERROR ) ==
36+ LIMA_GP_IRQ_PLBU_OUT_OF_MEM ) {
37+ dev_dbg (dev -> dev , "gp out of heap irq status=%x\n" ,
38+ status );
39+ } else {
40+ dev_err (dev -> dev , "gp error irq state=%x status=%x\n" ,
41+ state , status );
42+ if (task )
43+ task -> recoverable = false;
44+ }
3445
3546 /* mask all interrupts before hard reset */
3647 gp_write (LIMA_GP_INT_MASK , 0 );
@@ -43,6 +54,7 @@ static irqreturn_t lima_gp_irq_handler(int irq, void *data)
4354 bool active = status & (LIMA_GP_STATUS_VS_ACTIVE |
4455 LIMA_GP_STATUS_PLBU_ACTIVE );
4556 done = valid && !active ;
57+ pipe -> error = false;
4658 }
4759
4860 gp_write (LIMA_GP_INT_CLEAR , state );
@@ -121,6 +133,22 @@ static void lima_gp_task_run(struct lima_sched_pipe *pipe,
121133 u32 cmd = 0 ;
122134 int i ;
123135
136+ /* update real heap buffer size for GP */
137+ for (i = 0 ; i < task -> num_bos ; i ++ ) {
138+ struct lima_bo * bo = task -> bos [i ];
139+
140+ if (bo -> heap_size &&
141+ lima_vm_get_va (task -> vm , bo ) ==
142+ f [LIMA_GP_PLBU_ALLOC_START_ADDR >> 2 ]) {
143+ f [LIMA_GP_PLBU_ALLOC_END_ADDR >> 2 ] =
144+ f [LIMA_GP_PLBU_ALLOC_START_ADDR >> 2 ] +
145+ bo -> heap_size ;
146+ task -> recoverable = true;
147+ task -> heap = bo ;
148+ break ;
149+ }
150+ }
151+
124152 if (f [LIMA_GP_VSCL_START_ADDR >> 2 ] !=
125153 f [LIMA_GP_VSCL_END_ADDR >> 2 ])
126154 cmd |= LIMA_GP_CMD_START_VS ;
@@ -184,6 +212,31 @@ static void lima_gp_task_mmu_error(struct lima_sched_pipe *pipe)
184212 lima_sched_pipe_task_done (pipe );
185213}
186214
215+ static int lima_gp_task_recover (struct lima_sched_pipe * pipe )
216+ {
217+ struct lima_ip * ip = pipe -> processor [0 ];
218+ struct lima_sched_task * task = pipe -> current_task ;
219+ struct drm_lima_gp_frame * frame = task -> frame ;
220+ u32 * f = frame -> frame ;
221+ size_t fail_size =
222+ f [LIMA_GP_PLBU_ALLOC_END_ADDR >> 2 ] -
223+ f [LIMA_GP_PLBU_ALLOC_START_ADDR >> 2 ];
224+
225+ if (fail_size == task -> heap -> heap_size ) {
226+ int ret ;
227+
228+ ret = lima_heap_alloc (task -> heap , task -> vm );
229+ if (ret < 0 )
230+ return ret ;
231+ }
232+
233+ gp_write (LIMA_GP_INT_MASK , LIMA_GP_IRQ_MASK_USED );
234+ gp_write (LIMA_GP_PLBU_ALLOC_END_ADDR ,
235+ f [LIMA_GP_PLBU_ALLOC_START_ADDR >> 2 ] + task -> heap -> heap_size );
236+ gp_write (LIMA_GP_CMD , LIMA_GP_CMD_UPDATE_PLBU_ALLOC );
237+ return 0 ;
238+ }
239+
187240static void lima_gp_print_version (struct lima_ip * ip )
188241{
189242 u32 version , major , minor ;
@@ -270,6 +323,7 @@ int lima_gp_pipe_init(struct lima_device *dev)
270323 pipe -> task_fini = lima_gp_task_fini ;
271324 pipe -> task_error = lima_gp_task_error ;
272325 pipe -> task_mmu_error = lima_gp_task_mmu_error ;
326+ pipe -> task_recover = lima_gp_task_recover ;
273327
274328 return 0 ;
275329}
0 commit comments