Commit 2f9225db authored by Lucas Stach's avatar Lucas Stach

drm/etnaviv: move cmdbuf into submit object

Less dynamic allocations and slims down the cmdbuf object to only the
required information, as everything else is already available in the
submit object.

This also simplifies buffer and mappings lifetime management, as they
are now exlusively attached to the submit object and not additionally
to the cmdbuf.
Signed-off-by: default avatarLucas Stach <l.stach@pengutronix.de>
parent 7a9c0fe2
...@@ -166,7 +166,7 @@ static u32 etnaviv_buffer_reserve(struct etnaviv_gpu *gpu, ...@@ -166,7 +166,7 @@ static u32 etnaviv_buffer_reserve(struct etnaviv_gpu *gpu,
u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu) u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu)
{ {
struct etnaviv_cmdbuf *buffer = gpu->buffer; struct etnaviv_cmdbuf *buffer = &gpu->buffer;
lockdep_assert_held(&gpu->lock); lockdep_assert_held(&gpu->lock);
...@@ -182,7 +182,7 @@ u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu) ...@@ -182,7 +182,7 @@ u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu)
u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe_addr) u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe_addr)
{ {
struct etnaviv_cmdbuf *buffer = gpu->buffer; struct etnaviv_cmdbuf *buffer = &gpu->buffer;
lockdep_assert_held(&gpu->lock); lockdep_assert_held(&gpu->lock);
...@@ -217,7 +217,7 @@ u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe ...@@ -217,7 +217,7 @@ u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe
void etnaviv_buffer_end(struct etnaviv_gpu *gpu) void etnaviv_buffer_end(struct etnaviv_gpu *gpu)
{ {
struct etnaviv_cmdbuf *buffer = gpu->buffer; struct etnaviv_cmdbuf *buffer = &gpu->buffer;
unsigned int waitlink_offset = buffer->user_size - 16; unsigned int waitlink_offset = buffer->user_size - 16;
u32 link_target, flush = 0; u32 link_target, flush = 0;
...@@ -261,7 +261,7 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu) ...@@ -261,7 +261,7 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu)
/* Append a 'sync point' to the ring buffer. */ /* Append a 'sync point' to the ring buffer. */
void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event) void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event)
{ {
struct etnaviv_cmdbuf *buffer = gpu->buffer; struct etnaviv_cmdbuf *buffer = &gpu->buffer;
unsigned int waitlink_offset = buffer->user_size - 16; unsigned int waitlink_offset = buffer->user_size - 16;
u32 dwords, target; u32 dwords, target;
...@@ -300,7 +300,7 @@ void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event) ...@@ -300,7 +300,7 @@ void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event)
void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state, void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,
unsigned int event, struct etnaviv_cmdbuf *cmdbuf) unsigned int event, struct etnaviv_cmdbuf *cmdbuf)
{ {
struct etnaviv_cmdbuf *buffer = gpu->buffer; struct etnaviv_cmdbuf *buffer = &gpu->buffer;
unsigned int waitlink_offset = buffer->user_size - 16; unsigned int waitlink_offset = buffer->user_size - 16;
u32 return_target, return_dwords; u32 return_target, return_dwords;
u32 link_target, link_dwords; u32 link_target, link_dwords;
......
...@@ -86,19 +86,11 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc) ...@@ -86,19 +86,11 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc)
kfree(suballoc); kfree(suballoc);
} }
struct etnaviv_cmdbuf * int etnaviv_cmdbuf_init(struct etnaviv_cmdbuf_suballoc *suballoc,
etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, struct etnaviv_cmdbuf *cmdbuf, u32 size)
size_t nr_bos)
{ {
struct etnaviv_cmdbuf *cmdbuf;
size_t sz = size_vstruct(nr_bos, sizeof(cmdbuf->bo_map[0]),
sizeof(*cmdbuf));
int granule_offs, order, ret; int granule_offs, order, ret;
cmdbuf = kzalloc(sz, GFP_KERNEL);
if (!cmdbuf)
return NULL;
cmdbuf->suballoc = suballoc; cmdbuf->suballoc = suballoc;
cmdbuf->size = size; cmdbuf->size = size;
...@@ -116,7 +108,7 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, ...@@ -116,7 +108,7 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size,
if (!ret) { if (!ret) {
dev_err(suballoc->gpu->dev, dev_err(suballoc->gpu->dev,
"Timeout waiting for cmdbuf space\n"); "Timeout waiting for cmdbuf space\n");
return NULL; return -ETIMEDOUT;
} }
goto retry; goto retry;
} }
...@@ -124,7 +116,7 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, ...@@ -124,7 +116,7 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size,
cmdbuf->suballoc_offset = granule_offs * SUBALLOC_GRANULE; cmdbuf->suballoc_offset = granule_offs * SUBALLOC_GRANULE;
cmdbuf->vaddr = suballoc->vaddr + cmdbuf->suballoc_offset; cmdbuf->vaddr = suballoc->vaddr + cmdbuf->suballoc_offset;
return cmdbuf; return 0;
} }
void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf) void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf)
...@@ -140,7 +132,6 @@ void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf) ...@@ -140,7 +132,6 @@ void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf)
suballoc->free_space = 1; suballoc->free_space = 1;
mutex_unlock(&suballoc->lock); mutex_unlock(&suballoc->lock);
wake_up_all(&suballoc->free_event); wake_up_all(&suballoc->free_event);
kfree(cmdbuf);
} }
u32 etnaviv_cmdbuf_get_va(struct etnaviv_cmdbuf *buf) u32 etnaviv_cmdbuf_get_va(struct etnaviv_cmdbuf *buf)
......
...@@ -33,22 +33,15 @@ struct etnaviv_cmdbuf { ...@@ -33,22 +33,15 @@ struct etnaviv_cmdbuf {
void *vaddr; void *vaddr;
u32 size; u32 size;
u32 user_size; u32 user_size;
/* fence after which this buffer is to be disposed */
struct dma_fence *fence;
/* per GPU in-flight list */
struct list_head node;
/* BOs attached to this command buffer */
unsigned int nr_bos;
struct etnaviv_vram_mapping *bo_map[0];
}; };
struct etnaviv_cmdbuf_suballoc * struct etnaviv_cmdbuf_suballoc *
etnaviv_cmdbuf_suballoc_new(struct etnaviv_gpu * gpu); etnaviv_cmdbuf_suballoc_new(struct etnaviv_gpu * gpu);
void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc); void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc);
struct etnaviv_cmdbuf *
etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, int etnaviv_cmdbuf_init(struct etnaviv_cmdbuf_suballoc *suballoc,
size_t nr_bos); struct etnaviv_cmdbuf *cmdbuf, u32 size);
void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf); void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf);
u32 etnaviv_cmdbuf_get_va(struct etnaviv_cmdbuf *buf); u32 etnaviv_cmdbuf_get_va(struct etnaviv_cmdbuf *buf);
......
...@@ -172,7 +172,7 @@ static int etnaviv_mmu_show(struct etnaviv_gpu *gpu, struct seq_file *m) ...@@ -172,7 +172,7 @@ static int etnaviv_mmu_show(struct etnaviv_gpu *gpu, struct seq_file *m)
static void etnaviv_buffer_dump(struct etnaviv_gpu *gpu, struct seq_file *m) static void etnaviv_buffer_dump(struct etnaviv_gpu *gpu, struct seq_file *m)
{ {
struct etnaviv_cmdbuf *buf = gpu->buffer; struct etnaviv_cmdbuf *buf = &gpu->buffer;
u32 size = buf->size; u32 size = buf->size;
u32 *ptr = buf->vaddr; u32 *ptr = buf->vaddr;
u32 i; u32 i;
......
...@@ -120,7 +120,7 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu) ...@@ -120,7 +120,7 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu)
struct core_dump_iterator iter; struct core_dump_iterator iter;
struct etnaviv_vram_mapping *vram; struct etnaviv_vram_mapping *vram;
struct etnaviv_gem_object *obj; struct etnaviv_gem_object *obj;
struct etnaviv_cmdbuf *cmd; struct etnaviv_gem_submit *submit;
unsigned int n_obj, n_bomap_pages; unsigned int n_obj, n_bomap_pages;
size_t file_size, mmu_size; size_t file_size, mmu_size;
__le64 *bomap, *bomap_start; __le64 *bomap, *bomap_start;
...@@ -132,11 +132,11 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu) ...@@ -132,11 +132,11 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu)
n_bomap_pages = 0; n_bomap_pages = 0;
file_size = ARRAY_SIZE(etnaviv_dump_registers) * file_size = ARRAY_SIZE(etnaviv_dump_registers) *
sizeof(struct etnaviv_dump_registers) + sizeof(struct etnaviv_dump_registers) +
mmu_size + gpu->buffer->size; mmu_size + gpu->buffer.size;
/* Add in the active command buffers */ /* Add in the active command buffers */
list_for_each_entry(cmd, &gpu->active_cmd_list, node) { list_for_each_entry(submit, &gpu->active_submit_list, node) {
file_size += cmd->size; file_size += submit->cmdbuf.size;
n_obj++; n_obj++;
} }
...@@ -176,13 +176,14 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu) ...@@ -176,13 +176,14 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu)
etnaviv_core_dump_registers(&iter, gpu); etnaviv_core_dump_registers(&iter, gpu);
etnaviv_core_dump_mmu(&iter, gpu, mmu_size); etnaviv_core_dump_mmu(&iter, gpu, mmu_size);
etnaviv_core_dump_mem(&iter, ETDUMP_BUF_RING, gpu->buffer->vaddr, etnaviv_core_dump_mem(&iter, ETDUMP_BUF_RING, gpu->buffer.vaddr,
gpu->buffer->size, gpu->buffer.size,
etnaviv_cmdbuf_get_va(gpu->buffer)); etnaviv_cmdbuf_get_va(&gpu->buffer));
list_for_each_entry(cmd, &gpu->active_cmd_list, node) list_for_each_entry(submit, &gpu->active_submit_list, node)
etnaviv_core_dump_mem(&iter, ETDUMP_BUF_CMD, cmd->vaddr, etnaviv_core_dump_mem(&iter, ETDUMP_BUF_CMD,
cmd->size, etnaviv_cmdbuf_get_va(cmd)); submit->cmdbuf.vaddr, submit->cmdbuf.size,
etnaviv_cmdbuf_get_va(&submit->cmdbuf));
/* Reserve space for the bomap */ /* Reserve space for the bomap */
if (n_bomap_pages) { if (n_bomap_pages) {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#define __ETNAVIV_GEM_H__ #define __ETNAVIV_GEM_H__
#include <linux/reservation.h> #include <linux/reservation.h>
#include "etnaviv_cmdbuf.h"
#include "etnaviv_drv.h" #include "etnaviv_drv.h"
struct dma_fence; struct dma_fence;
...@@ -103,6 +104,8 @@ struct etnaviv_gem_submit { ...@@ -103,6 +104,8 @@ struct etnaviv_gem_submit {
struct kref refcount; struct kref refcount;
struct etnaviv_gpu *gpu; struct etnaviv_gpu *gpu;
struct dma_fence *out_fence, *in_fence; struct dma_fence *out_fence, *in_fence;
struct list_head node; /* GPU active submit list */
struct etnaviv_cmdbuf cmdbuf;
u32 exec_state; u32 exec_state;
u32 flags; u32 flags;
unsigned int nr_pmrs; unsigned int nr_pmrs;
......
...@@ -354,6 +354,9 @@ static void submit_cleanup(struct kref *kref) ...@@ -354,6 +354,9 @@ static void submit_cleanup(struct kref *kref)
container_of(kref, struct etnaviv_gem_submit, refcount); container_of(kref, struct etnaviv_gem_submit, refcount);
unsigned i; unsigned i;
if (submit->cmdbuf.suballoc)
etnaviv_cmdbuf_free(&submit->cmdbuf);
for (i = 0; i < submit->nr_bos; i++) { for (i = 0; i < submit->nr_bos; i++) {
struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj; struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj;
...@@ -391,7 +394,6 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -391,7 +394,6 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
struct drm_etnaviv_gem_submit_pmr *pmrs; struct drm_etnaviv_gem_submit_pmr *pmrs;
struct drm_etnaviv_gem_submit_bo *bos; struct drm_etnaviv_gem_submit_bo *bos;
struct etnaviv_gem_submit *submit; struct etnaviv_gem_submit *submit;
struct etnaviv_cmdbuf *cmdbuf;
struct etnaviv_gpu *gpu; struct etnaviv_gpu *gpu;
struct sync_file *sync_file = NULL; struct sync_file *sync_file = NULL;
struct ww_acquire_ctx ticket; struct ww_acquire_ctx ticket;
...@@ -432,16 +434,11 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -432,16 +434,11 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
relocs = kvmalloc_array(args->nr_relocs, sizeof(*relocs), GFP_KERNEL); relocs = kvmalloc_array(args->nr_relocs, sizeof(*relocs), GFP_KERNEL);
pmrs = kvmalloc_array(args->nr_pmrs, sizeof(*pmrs), GFP_KERNEL); pmrs = kvmalloc_array(args->nr_pmrs, sizeof(*pmrs), GFP_KERNEL);
stream = kvmalloc_array(1, args->stream_size, GFP_KERNEL); stream = kvmalloc_array(1, args->stream_size, GFP_KERNEL);
cmdbuf = etnaviv_cmdbuf_new(gpu->cmdbuf_suballoc, if (!bos || !relocs || !pmrs || !stream) {
ALIGN(args->stream_size, 8) + 8,
args->nr_bos);
if (!bos || !relocs || !pmrs || !stream || !cmdbuf) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_submit_cmds; goto err_submit_cmds;
} }
cmdbuf->ctx = file->driver_priv;
ret = copy_from_user(bos, u64_to_user_ptr(args->bos), ret = copy_from_user(bos, u64_to_user_ptr(args->bos),
args->nr_bos * sizeof(*bos)); args->nr_bos * sizeof(*bos));
if (ret) { if (ret) {
...@@ -486,6 +483,12 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -486,6 +483,12 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
goto err_submit_ww_acquire; goto err_submit_ww_acquire;
} }
ret = etnaviv_cmdbuf_init(gpu->cmdbuf_suballoc, &submit->cmdbuf,
ALIGN(args->stream_size, 8) + 8);
if (ret)
goto err_submit_objects;
submit->cmdbuf.ctx = file->driver_priv;
submit->exec_state = args->exec_state; submit->exec_state = args->exec_state;
submit->flags = args->flags; submit->flags = args->flags;
...@@ -528,17 +531,15 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -528,17 +531,15 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
if (ret) if (ret)
goto err_submit_objects; goto err_submit_objects;
memcpy(cmdbuf->vaddr, stream, args->stream_size); memcpy(submit->cmdbuf.vaddr, stream, args->stream_size);
cmdbuf->user_size = ALIGN(args->stream_size, 8); submit->cmdbuf.user_size = ALIGN(args->stream_size, 8);
ret = etnaviv_gpu_submit(gpu, submit, cmdbuf); ret = etnaviv_gpu_submit(gpu, submit);
if (ret) if (ret)
goto err_submit_objects; goto err_submit_objects;
submit_attach_object_fences(submit); submit_attach_object_fences(submit);
cmdbuf = NULL;
if (args->flags & ETNA_SUBMIT_FENCE_FD_OUT) { if (args->flags & ETNA_SUBMIT_FENCE_FD_OUT) {
/* /*
* This can be improved: ideally we want to allocate the sync * This can be improved: ideally we want to allocate the sync
...@@ -566,9 +567,6 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -566,9 +567,6 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
err_submit_cmds: err_submit_cmds:
if (ret && (out_fence_fd >= 0)) if (ret && (out_fence_fd >= 0))
put_unused_fd(out_fence_fd); put_unused_fd(out_fence_fd);
/* if we still own the cmdbuf */
if (cmdbuf)
etnaviv_cmdbuf_free(cmdbuf);
if (stream) if (stream)
kvfree(stream); kvfree(stream);
if (bos) if (bos)
......
...@@ -644,7 +644,7 @@ static void etnaviv_gpu_hw_init(struct etnaviv_gpu *gpu) ...@@ -644,7 +644,7 @@ static void etnaviv_gpu_hw_init(struct etnaviv_gpu *gpu)
prefetch = etnaviv_buffer_init(gpu); prefetch = etnaviv_buffer_init(gpu);
gpu_write(gpu, VIVS_HI_INTR_ENBL, ~0U); gpu_write(gpu, VIVS_HI_INTR_ENBL, ~0U);
etnaviv_gpu_start_fe(gpu, etnaviv_cmdbuf_get_va(gpu->buffer), etnaviv_gpu_start_fe(gpu, etnaviv_cmdbuf_get_va(&gpu->buffer),
prefetch); prefetch);
} }
...@@ -717,15 +717,15 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu) ...@@ -717,15 +717,15 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
} }
/* Create buffer: */ /* Create buffer: */
gpu->buffer = etnaviv_cmdbuf_new(gpu->cmdbuf_suballoc, PAGE_SIZE, 0); ret = etnaviv_cmdbuf_init(gpu->cmdbuf_suballoc, &gpu->buffer,
if (!gpu->buffer) { PAGE_SIZE);
ret = -ENOMEM; if (ret) {
dev_err(gpu->dev, "could not create command buffer\n"); dev_err(gpu->dev, "could not create command buffer\n");
goto destroy_iommu; goto destroy_iommu;
} }
if (gpu->mmu->version == ETNAVIV_IOMMU_V1 && if (gpu->mmu->version == ETNAVIV_IOMMU_V1 &&
etnaviv_cmdbuf_get_va(gpu->buffer) > 0x80000000) { etnaviv_cmdbuf_get_va(&gpu->buffer) > 0x80000000) {
ret = -EINVAL; ret = -EINVAL;
dev_err(gpu->dev, dev_err(gpu->dev,
"command buffer outside valid memory window\n"); "command buffer outside valid memory window\n");
...@@ -751,8 +751,7 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu) ...@@ -751,8 +751,7 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
return 0; return 0;
free_buffer: free_buffer:
etnaviv_cmdbuf_free(gpu->buffer); etnaviv_cmdbuf_free(&gpu->buffer);
gpu->buffer = NULL;
destroy_iommu: destroy_iommu:
etnaviv_iommu_destroy(gpu->mmu); etnaviv_iommu_destroy(gpu->mmu);
gpu->mmu = NULL; gpu->mmu = NULL;
...@@ -1201,27 +1200,20 @@ static void retire_worker(struct work_struct *work) ...@@ -1201,27 +1200,20 @@ static void retire_worker(struct work_struct *work)
struct etnaviv_gpu *gpu = container_of(work, struct etnaviv_gpu, struct etnaviv_gpu *gpu = container_of(work, struct etnaviv_gpu,
retire_work); retire_work);
u32 fence = gpu->completed_fence; u32 fence = gpu->completed_fence;
struct etnaviv_cmdbuf *cmdbuf, *tmp; struct etnaviv_gem_submit *submit, *tmp;
unsigned int i; unsigned int i;
mutex_lock(&gpu->lock); mutex_lock(&gpu->lock);
list_for_each_entry_safe(cmdbuf, tmp, &gpu->active_cmd_list, node) { list_for_each_entry_safe(submit, tmp, &gpu->active_submit_list, node) {
if (!dma_fence_is_signaled(cmdbuf->fence)) if (!dma_fence_is_signaled(submit->out_fence))
break; break;
list_del(&cmdbuf->node); list_del(&submit->node);
dma_fence_put(cmdbuf->fence);
for (i = 0; i < cmdbuf->nr_bos; i++) { for (i = 0; i < submit->nr_bos; i++)
struct etnaviv_vram_mapping *mapping = cmdbuf->bo_map[i]; atomic_dec(&submit->bos[i].obj->gpu_active);
struct etnaviv_gem_object *etnaviv_obj = mapping->object;
atomic_dec(&etnaviv_obj->gpu_active);
/* drop the refcount taken in etnaviv_gpu_submit */
etnaviv_gem_mapping_unreference(mapping);
}
etnaviv_cmdbuf_free(cmdbuf); etnaviv_submit_put(submit);
/* /*
* We need to balance the runtime PM count caused by * We need to balance the runtime PM count caused by
* each submission. Upon submission, we increment * each submission. Upon submission, we increment
...@@ -1375,9 +1367,8 @@ static void sync_point_perfmon_sample_post(struct etnaviv_gpu *gpu, ...@@ -1375,9 +1367,8 @@ static void sync_point_perfmon_sample_post(struct etnaviv_gpu *gpu,
/* add bo's to gpu's ring, and kick gpu: */ /* add bo's to gpu's ring, and kick gpu: */
int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
struct etnaviv_gem_submit *submit, struct etnaviv_cmdbuf *cmdbuf) struct etnaviv_gem_submit *submit)
{ {
struct dma_fence *fence;
unsigned int i, nr_events = 1, event[3]; unsigned int i, nr_events = 1, event[3];
int ret; int ret;
...@@ -1403,8 +1394,8 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, ...@@ -1403,8 +1394,8 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
mutex_lock(&gpu->lock); mutex_lock(&gpu->lock);
fence = etnaviv_gpu_fence_alloc(gpu); submit->out_fence = etnaviv_gpu_fence_alloc(gpu);
if (!fence) { if (!submit->out_fence) {
for (i = 0; i < nr_events; i++) for (i = 0; i < nr_events; i++)
event_free(gpu, event[i]); event_free(gpu, event[i]);
...@@ -1412,8 +1403,6 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, ...@@ -1412,8 +1403,6 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
goto out_unlock; goto out_unlock;
} }
gpu->event[event[0]].fence = fence;
submit->out_fence = dma_fence_get(fence);
gpu->active_fence = submit->out_fence->seqno; gpu->active_fence = submit->out_fence->seqno;
if (submit->nr_pmrs) { if (submit->nr_pmrs) {
...@@ -1423,7 +1412,10 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, ...@@ -1423,7 +1412,10 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
etnaviv_sync_point_queue(gpu, event[1]); etnaviv_sync_point_queue(gpu, event[1]);
} }
etnaviv_buffer_queue(gpu, submit->exec_state, event[0], cmdbuf); kref_get(&submit->refcount);
gpu->event[event[0]].fence = submit->out_fence;
etnaviv_buffer_queue(gpu, submit->exec_state, event[0],
&submit->cmdbuf);
if (submit->nr_pmrs) { if (submit->nr_pmrs) {
gpu->event[event[2]].sync_point = &sync_point_perfmon_sample_post; gpu->event[event[2]].sync_point = &sync_point_perfmon_sample_post;
...@@ -1432,21 +1424,15 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, ...@@ -1432,21 +1424,15 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
etnaviv_sync_point_queue(gpu, event[2]); etnaviv_sync_point_queue(gpu, event[2]);
} }
cmdbuf->fence = fence; list_add_tail(&submit->node, &gpu->active_submit_list);
list_add_tail(&cmdbuf->node, &gpu->active_cmd_list);
/* We're committed to adding this command buffer, hold a PM reference */ /* We're committed to adding this command buffer, hold a PM reference */
pm_runtime_get_noresume(gpu->dev); pm_runtime_get_noresume(gpu->dev);
for (i = 0; i < submit->nr_bos; i++) { for (i = 0; i < submit->nr_bos; i++) {
struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj; struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj;
/* Each cmdbuf takes a refcount on the mapping */
etnaviv_gem_mapping_reference(submit->bos[i].mapping);
cmdbuf->bo_map[i] = submit->bos[i].mapping;
atomic_inc(&etnaviv_obj->gpu_active); atomic_inc(&etnaviv_obj->gpu_active);
} }
cmdbuf->nr_bos = submit->nr_bos;
hangcheck_timer_reset(gpu); hangcheck_timer_reset(gpu);
ret = 0; ret = 0;
...@@ -1625,7 +1611,7 @@ int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms) ...@@ -1625,7 +1611,7 @@ int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms)
static int etnaviv_gpu_hw_suspend(struct etnaviv_gpu *gpu) static int etnaviv_gpu_hw_suspend(struct etnaviv_gpu *gpu)
{ {
if (gpu->buffer) { if (gpu->buffer.suballoc) {
/* Replace the last WAIT with END */ /* Replace the last WAIT with END */
mutex_lock(&gpu->lock); mutex_lock(&gpu->lock);
etnaviv_buffer_end(gpu); etnaviv_buffer_end(gpu);
...@@ -1742,7 +1728,7 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master, ...@@ -1742,7 +1728,7 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master,
gpu->fence_context = dma_fence_context_alloc(1); gpu->fence_context = dma_fence_context_alloc(1);
spin_lock_init(&gpu->fence_spinlock); spin_lock_init(&gpu->fence_spinlock);
INIT_LIST_HEAD(&gpu->active_cmd_list); INIT_LIST_HEAD(&gpu->active_submit_list);
INIT_WORK(&gpu->retire_work, retire_worker); INIT_WORK(&gpu->retire_work, retire_worker);
INIT_WORK(&gpu->sync_point_work, sync_point_worker); INIT_WORK(&gpu->sync_point_work, sync_point_worker);
INIT_WORK(&gpu->recover_work, recover_worker); INIT_WORK(&gpu->recover_work, recover_worker);
...@@ -1777,10 +1763,8 @@ static void etnaviv_gpu_unbind(struct device *dev, struct device *master, ...@@ -1777,10 +1763,8 @@ static void etnaviv_gpu_unbind(struct device *dev, struct device *master,
etnaviv_gpu_hw_suspend(gpu); etnaviv_gpu_hw_suspend(gpu);
#endif #endif
if (gpu->buffer) { if (gpu->buffer.suballoc)
etnaviv_cmdbuf_free(gpu->buffer); etnaviv_cmdbuf_free(&gpu->buffer);
gpu->buffer = NULL;
}
if (gpu->cmdbuf_suballoc) { if (gpu->cmdbuf_suballoc) {
etnaviv_cmdbuf_suballoc_destroy(gpu->cmdbuf_suballoc); etnaviv_cmdbuf_suballoc_destroy(gpu->cmdbuf_suballoc);
...@@ -1918,7 +1902,7 @@ static int etnaviv_gpu_rpm_resume(struct device *dev) ...@@ -1918,7 +1902,7 @@ static int etnaviv_gpu_rpm_resume(struct device *dev)
return ret; return ret;
/* Re-initialise the basic hardware state */ /* Re-initialise the basic hardware state */
if (gpu->drm && gpu->buffer) { if (gpu->drm && gpu->buffer.suballoc) {
ret = etnaviv_gpu_hw_resume(gpu); ret = etnaviv_gpu_hw_resume(gpu);
if (ret) { if (ret) {
etnaviv_gpu_clk_disable(gpu); etnaviv_gpu_clk_disable(gpu);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include "etnaviv_cmdbuf.h"
#include "etnaviv_drv.h" #include "etnaviv_drv.h"
struct etnaviv_gem_submit; struct etnaviv_gem_submit;
...@@ -109,7 +110,7 @@ struct etnaviv_gpu { ...@@ -109,7 +110,7 @@ struct etnaviv_gpu {
struct workqueue_struct *wq; struct workqueue_struct *wq;
/* 'ring'-buffer: */ /* 'ring'-buffer: */
struct etnaviv_cmdbuf *buffer; struct etnaviv_cmdbuf buffer;
int exec_state; int exec_state;
/* bus base address of memory */ /* bus base address of memory */
...@@ -122,7 +123,7 @@ struct etnaviv_gpu { ...@@ -122,7 +123,7 @@ struct etnaviv_gpu {
spinlock_t event_spinlock; spinlock_t event_spinlock;
/* list of currently in-flight command buffers */ /* list of currently in-flight command buffers */
struct list_head active_cmd_list; struct list_head active_submit_list;
u32 idle_mask; u32 idle_mask;
...@@ -202,7 +203,7 @@ int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu, ...@@ -202,7 +203,7 @@ int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu, int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout); struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout);
int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
struct etnaviv_gem_submit *submit, struct etnaviv_cmdbuf *cmdbuf); struct etnaviv_gem_submit *submit);
int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu); int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu);
void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu); void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu);
int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms); int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms);
......
...@@ -229,7 +229,7 @@ void etnaviv_iommuv2_restore(struct etnaviv_gpu *gpu) ...@@ -229,7 +229,7 @@ void etnaviv_iommuv2_restore(struct etnaviv_gpu *gpu)
prefetch = etnaviv_buffer_config_mmuv2(gpu, prefetch = etnaviv_buffer_config_mmuv2(gpu,
(u32)etnaviv_domain->mtlb_dma, (u32)etnaviv_domain->mtlb_dma,
(u32)etnaviv_domain->base.bad_page_dma); (u32)etnaviv_domain->base.bad_page_dma);
etnaviv_gpu_start_fe(gpu, (u32)etnaviv_cmdbuf_get_pa(gpu->buffer), etnaviv_gpu_start_fe(gpu, (u32)etnaviv_cmdbuf_get_pa(&gpu->buffer),
prefetch); prefetch);
etnaviv_gpu_wait_idle(gpu, 100); etnaviv_gpu_wait_idle(gpu, 100);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment