Skip to content

Commit 2081e8d

Browse files
committed
drm/lima: recover task by enlarging heap buffer
Increase heap buffer backup memory when GP receive PLBU out of memory interrupt, then resume the task. Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com> Tested-by: Andreas Baierl <ichgeh@imkreisrum.de> Signed-off-by: Qiang Yu <yuq825@gmail.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200116131157.13346-5-yuq825@gmail.com
1 parent 6aebc51 commit 2081e8d

5 files changed

Lines changed: 98 additions & 7 deletions

File tree

‎drivers/gpu/drm/lima/lima_gp.c‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
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+
187240
static 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
}

‎drivers/gpu/drm/lima/lima_mmu.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ void lima_mmu_fini(struct lima_ip *ip)
9999

100100
}
101101

102+
void lima_mmu_flush_tlb(struct lima_ip *ip)
103+
{
104+
mmu_write(LIMA_MMU_COMMAND, LIMA_MMU_COMMAND_ZAP_CACHE);
105+
}
106+
102107
void lima_mmu_switch_vm(struct lima_ip *ip, struct lima_vm *vm)
103108
{
104109
struct lima_device *dev = ip->dev;

‎drivers/gpu/drm/lima/lima_mmu.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct lima_vm;
1010
int lima_mmu_init(struct lima_ip *ip);
1111
void lima_mmu_fini(struct lima_ip *ip);
1212

13+
void lima_mmu_flush_tlb(struct lima_ip *ip);
1314
void lima_mmu_switch_vm(struct lima_ip *ip, struct lima_vm *vm);
1415
void lima_mmu_page_fault_resume(struct lima_ip *ip);
1516

‎drivers/gpu/drm/lima/lima_sched.c‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,26 @@ static const struct drm_sched_backend_ops lima_sched_ops = {
312312
.free_job = lima_sched_free_job,
313313
};
314314

315+
static void lima_sched_recover_work(struct work_struct *work)
316+
{
317+
struct lima_sched_pipe *pipe =
318+
container_of(work, struct lima_sched_pipe, recover_work);
319+
int i;
320+
321+
for (i = 0; i < pipe->num_l2_cache; i++)
322+
lima_l2_cache_flush(pipe->l2_cache[i]);
323+
324+
if (pipe->bcast_mmu) {
325+
lima_mmu_flush_tlb(pipe->bcast_mmu);
326+
} else {
327+
for (i = 0; i < pipe->num_mmu; i++)
328+
lima_mmu_flush_tlb(pipe->mmu[i]);
329+
}
330+
331+
if (pipe->task_recover(pipe))
332+
drm_sched_fault(&pipe->base);
333+
}
334+
315335
int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)
316336
{
317337
unsigned int timeout = lima_sched_timeout_ms > 0 ?
@@ -320,6 +340,8 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)
320340
pipe->fence_context = dma_fence_context_alloc(1);
321341
spin_lock_init(&pipe->fence_lock);
322342

343+
INIT_WORK(&pipe->recover_work, lima_sched_recover_work);
344+
323345
return drm_sched_init(&pipe->base, &lima_sched_ops, 1, 0,
324346
msecs_to_jiffies(timeout), name);
325347
}
@@ -331,11 +353,14 @@ void lima_sched_pipe_fini(struct lima_sched_pipe *pipe)
331353

332354
void lima_sched_pipe_task_done(struct lima_sched_pipe *pipe)
333355
{
334-
if (pipe->error)
335-
drm_sched_fault(&pipe->base);
336-
else {
337-
struct lima_sched_task *task = pipe->current_task;
338-
356+
struct lima_sched_task *task = pipe->current_task;
357+
358+
if (pipe->error) {
359+
if (task && task->recoverable)
360+
schedule_work(&pipe->recover_work);
361+
else
362+
drm_sched_fault(&pipe->base);
363+
} else {
339364
pipe->task_fini(pipe);
340365
dma_fence_signal(task->fence);
341366
}

‎drivers/gpu/drm/lima/lima_sched.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ struct lima_sched_task {
2020
struct lima_bo **bos;
2121
int num_bos;
2222

23+
bool recoverable;
24+
struct lima_bo *heap;
25+
2326
/* pipe fence */
2427
struct dma_fence *fence;
2528
};
@@ -68,6 +71,9 @@ struct lima_sched_pipe {
6871
void (*task_fini)(struct lima_sched_pipe *pipe);
6972
void (*task_error)(struct lima_sched_pipe *pipe);
7073
void (*task_mmu_error)(struct lima_sched_pipe *pipe);
74+
int (*task_recover)(struct lima_sched_pipe *pipe);
75+
76+
struct work_struct recover_work;
7177
};
7278

7379
int lima_sched_task_init(struct lima_sched_task *task,

0 commit comments

Comments
 (0)