Commit 787e1b74 authored by Dave Airlie's avatar Dave Airlie

Merge branch 'etnaviv/next' of https://git.pengutronix.de/git/lst/linux into drm-next

Most notable addition this time is the support for the GPU performance
counters by Christian. This has been in the making for some time and it
has matured a lot. Since this is adding UAPI, the corresponding WIP
userspace can be found at [1] mesa/libdrm repos. I expect that
Christian sends out the final userspace patches for this once you have
pulled the kernel bits.

Philipp optimized the probe path, so etnaviv gets out of the way for
systems that want to boot real quick.

I've done mostly cleanups, disentangling etnaviv from the IOMMU API,
with some MMUv1 optimizations on the way.

* 'etnaviv/next' of https://git.pengutronix.de/git/lst/linux: (36 commits)
  drm/etnaviv: remove unnecessary clock stabilization delay
  drm/etnaviv: reduce reset delay
  drm/etnaviv: remove unused function etnaviv_gem_new
  drm/etnaviv: remove stale comment
  drm/etnaviv: submit supports performance monitor requests
  drm/etnaviv: enable debug registers on demand
  drm/etnaviv: need to disable clock gating when doing profiling
  drm/etnaviv: add MC perf domain
  drm/etnaviv: add TX perf domain
  drm/etnaviv: add RA perf domain
  drm/etnaviv: add SE perf domain
  drm/etnaviv: add PA perf domain
  drm/etnaviv: add SH perf domain
  drm/etnaviv: add PE perf domain
  drm/etnaviv: add HI perf domain
  drm/etnaviv: use 'sync points' for performance monitor requests
  drm/etnaviv: clear alloced event
  drm/etnaviv: add 'sync point' support
  drm/etnaviv: add performance monitor request processing
  drm/etnaviv: copy pmrs from userspace
  ...
parents 972805c1 8272170f
...@@ -7,8 +7,6 @@ config DRM_ETNAVIV ...@@ -7,8 +7,6 @@ config DRM_ETNAVIV
select SHMEM select SHMEM
select SYNC_FILE select SYNC_FILE
select TMPFS select TMPFS
select IOMMU_API
select IOMMU_SUPPORT
select WANT_DEV_COREDUMP select WANT_DEV_COREDUMP
select CMA if HAVE_DMA_CONTIGUOUS select CMA if HAVE_DMA_CONTIGUOUS
select DMA_CMA if HAVE_DMA_CONTIGUOUS select DMA_CMA if HAVE_DMA_CONTIGUOUS
......
...@@ -10,6 +10,7 @@ etnaviv-y := \ ...@@ -10,6 +10,7 @@ etnaviv-y := \
etnaviv_gpu.o \ etnaviv_gpu.o \
etnaviv_iommu_v2.o \ etnaviv_iommu_v2.o \
etnaviv_iommu.o \ etnaviv_iommu.o \
etnaviv_mmu.o etnaviv_mmu.o \
etnaviv_perfmon.o
obj-$(CONFIG_DRM_ETNAVIV) += etnaviv.o obj-$(CONFIG_DRM_ETNAVIV) += etnaviv.o
...@@ -250,6 +250,42 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu) ...@@ -250,6 +250,42 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu)
} }
} }
/* Append a 'sync point' to the ring buffer. */
void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event)
{
struct etnaviv_cmdbuf *buffer = gpu->buffer;
unsigned int waitlink_offset = buffer->user_size - 16;
u32 dwords, target;
/*
* We need at most 3 dwords in the return target:
* 1 event + 1 end + 1 wait + 1 link.
*/
dwords = 4;
target = etnaviv_buffer_reserve(gpu, buffer, dwords);
/* Signal sync point event */
CMD_LOAD_STATE(buffer, VIVS_GL_EVENT, VIVS_GL_EVENT_EVENT_ID(event) |
VIVS_GL_EVENT_FROM_PE);
/* Stop the FE to 'pause' the GPU */
CMD_END(buffer);
/* Append waitlink */
CMD_WAIT(buffer);
CMD_LINK(buffer, 2, etnaviv_cmdbuf_get_va(buffer) +
buffer->user_size - 4);
/*
* Kick off the 'sync point' command by replacing the previous
* WAIT with a link to the address in the ring buffer.
*/
etnaviv_buffer_replace_wait(buffer, waitlink_offset,
VIV_FE_LINK_HEADER_OP_LINK |
VIV_FE_LINK_HEADER_PREFETCH(dwords),
target);
}
/* Append a command buffer to the ring buffer. */ /* Append a command buffer to the ring buffer. */
void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event, void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event,
struct etnaviv_cmdbuf *cmdbuf) struct etnaviv_cmdbuf *cmdbuf)
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "etnaviv_cmdbuf.h" #include "etnaviv_cmdbuf.h"
#include "etnaviv_gpu.h" #include "etnaviv_gpu.h"
#include "etnaviv_mmu.h" #include "etnaviv_mmu.h"
#include "etnaviv_perfmon.h"
#define SUBALLOC_SIZE SZ_256K #define SUBALLOC_SIZE SZ_256K
#define SUBALLOC_GRANULE SZ_4K #define SUBALLOC_GRANULE SZ_4K
...@@ -87,9 +88,10 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc) ...@@ -87,9 +88,10 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc)
struct etnaviv_cmdbuf * struct etnaviv_cmdbuf *
etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size,
size_t nr_bos) size_t nr_bos, size_t nr_pmrs)
{ {
struct etnaviv_cmdbuf *cmdbuf; struct etnaviv_cmdbuf *cmdbuf;
struct etnaviv_perfmon_request *pmrs;
size_t sz = size_vstruct(nr_bos, sizeof(cmdbuf->bo_map[0]), size_t sz = size_vstruct(nr_bos, sizeof(cmdbuf->bo_map[0]),
sizeof(*cmdbuf)); sizeof(*cmdbuf));
int granule_offs, order, ret; int granule_offs, order, ret;
...@@ -98,6 +100,12 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, ...@@ -98,6 +100,12 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size,
if (!cmdbuf) if (!cmdbuf)
return NULL; return NULL;
sz = sizeof(*pmrs) * nr_pmrs;
pmrs = kzalloc(sz, GFP_KERNEL);
if (!pmrs)
goto out_free_cmdbuf;
cmdbuf->pmrs = pmrs;
cmdbuf->suballoc = suballoc; cmdbuf->suballoc = suballoc;
cmdbuf->size = size; cmdbuf->size = size;
...@@ -124,6 +132,10 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, ...@@ -124,6 +132,10 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size,
cmdbuf->vaddr = suballoc->vaddr + cmdbuf->suballoc_offset; cmdbuf->vaddr = suballoc->vaddr + cmdbuf->suballoc_offset;
return cmdbuf; return cmdbuf;
out_free_cmdbuf:
kfree(cmdbuf);
return NULL;
} }
void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf) void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf)
...@@ -139,6 +151,7 @@ void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf) ...@@ -139,6 +151,7 @@ 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->pmrs);
kfree(cmdbuf); kfree(cmdbuf);
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
struct etnaviv_gpu; struct etnaviv_gpu;
struct etnaviv_cmdbuf_suballoc; struct etnaviv_cmdbuf_suballoc;
struct etnaviv_perfmon_request;
struct etnaviv_cmdbuf { struct etnaviv_cmdbuf {
/* suballocator this cmdbuf is allocated from */ /* suballocator this cmdbuf is allocated from */
...@@ -38,6 +39,9 @@ struct etnaviv_cmdbuf { ...@@ -38,6 +39,9 @@ struct etnaviv_cmdbuf {
u32 exec_state; u32 exec_state;
/* per GPU in-flight list */ /* per GPU in-flight list */
struct list_head node; struct list_head node;
/* perfmon requests */
unsigned int nr_pmrs;
struct etnaviv_perfmon_request *pmrs;
/* BOs attached to this command buffer */ /* BOs attached to this command buffer */
unsigned int nr_bos; unsigned int nr_bos;
struct etnaviv_vram_mapping *bo_map[0]; struct etnaviv_vram_mapping *bo_map[0];
...@@ -49,7 +53,7 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc); ...@@ -49,7 +53,7 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc);
struct etnaviv_cmdbuf * struct etnaviv_cmdbuf *
etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size,
size_t nr_bos); size_t nr_bos, size_t nr_pmrs);
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);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "etnaviv_gpu.h" #include "etnaviv_gpu.h"
#include "etnaviv_gem.h" #include "etnaviv_gem.h"
#include "etnaviv_mmu.h" #include "etnaviv_mmu.h"
#include "etnaviv_perfmon.h"
#ifdef CONFIG_DRM_ETNAVIV_REGISTER_LOGGING #ifdef CONFIG_DRM_ETNAVIV_REGISTER_LOGGING
static bool reglog; static bool reglog;
...@@ -451,6 +452,40 @@ static int etnaviv_ioctl_gem_wait(struct drm_device *dev, void *data, ...@@ -451,6 +452,40 @@ static int etnaviv_ioctl_gem_wait(struct drm_device *dev, void *data,
return ret; return ret;
} }
static int etnaviv_ioctl_pm_query_dom(struct drm_device *dev, void *data,
struct drm_file *file)
{
struct etnaviv_drm_private *priv = dev->dev_private;
struct drm_etnaviv_pm_domain *args = data;
struct etnaviv_gpu *gpu;
if (args->pipe >= ETNA_MAX_PIPES)
return -EINVAL;
gpu = priv->gpu[args->pipe];
if (!gpu)
return -ENXIO;
return etnaviv_pm_query_dom(gpu, args);
}
static int etnaviv_ioctl_pm_query_sig(struct drm_device *dev, void *data,
struct drm_file *file)
{
struct etnaviv_drm_private *priv = dev->dev_private;
struct drm_etnaviv_pm_signal *args = data;
struct etnaviv_gpu *gpu;
if (args->pipe >= ETNA_MAX_PIPES)
return -EINVAL;
gpu = priv->gpu[args->pipe];
if (!gpu)
return -ENXIO;
return etnaviv_pm_query_sig(gpu, args);
}
static const struct drm_ioctl_desc etnaviv_ioctls[] = { static const struct drm_ioctl_desc etnaviv_ioctls[] = {
#define ETNA_IOCTL(n, func, flags) \ #define ETNA_IOCTL(n, func, flags) \
DRM_IOCTL_DEF_DRV(ETNAVIV_##n, etnaviv_ioctl_##func, flags) DRM_IOCTL_DEF_DRV(ETNAVIV_##n, etnaviv_ioctl_##func, flags)
...@@ -463,6 +498,8 @@ static const struct drm_ioctl_desc etnaviv_ioctls[] = { ...@@ -463,6 +498,8 @@ static const struct drm_ioctl_desc etnaviv_ioctls[] = {
ETNA_IOCTL(WAIT_FENCE, wait_fence, DRM_AUTH|DRM_RENDER_ALLOW), ETNA_IOCTL(WAIT_FENCE, wait_fence, DRM_AUTH|DRM_RENDER_ALLOW),
ETNA_IOCTL(GEM_USERPTR, gem_userptr, DRM_AUTH|DRM_RENDER_ALLOW), ETNA_IOCTL(GEM_USERPTR, gem_userptr, DRM_AUTH|DRM_RENDER_ALLOW),
ETNA_IOCTL(GEM_WAIT, gem_wait, DRM_AUTH|DRM_RENDER_ALLOW), ETNA_IOCTL(GEM_WAIT, gem_wait, DRM_AUTH|DRM_RENDER_ALLOW),
ETNA_IOCTL(PM_QUERY_DOM, pm_query_dom, DRM_AUTH|DRM_RENDER_ALLOW),
ETNA_IOCTL(PM_QUERY_SIG, pm_query_sig, DRM_AUTH|DRM_RENDER_ALLOW),
}; };
static const struct vm_operations_struct vm_ops = { static const struct vm_operations_struct vm_ops = {
...@@ -513,7 +550,7 @@ static struct drm_driver etnaviv_drm_driver = { ...@@ -513,7 +550,7 @@ static struct drm_driver etnaviv_drm_driver = {
.desc = "etnaviv DRM", .desc = "etnaviv DRM",
.date = "20151214", .date = "20151214",
.major = 1, .major = 1,
.minor = 1, .minor = 2,
}; };
/* /*
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/iommu.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/sizes.h> #include <linux/sizes.h>
...@@ -92,15 +91,12 @@ int etnaviv_gem_cpu_fini(struct drm_gem_object *obj); ...@@ -92,15 +91,12 @@ int etnaviv_gem_cpu_fini(struct drm_gem_object *obj);
void etnaviv_gem_free_object(struct drm_gem_object *obj); void etnaviv_gem_free_object(struct drm_gem_object *obj);
int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file, int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
u32 size, u32 flags, u32 *handle); u32 size, u32 flags, u32 *handle);
struct drm_gem_object *etnaviv_gem_new_locked(struct drm_device *dev,
u32 size, u32 flags);
struct drm_gem_object *etnaviv_gem_new(struct drm_device *dev,
u32 size, u32 flags);
int etnaviv_gem_new_userptr(struct drm_device *dev, struct drm_file *file, int etnaviv_gem_new_userptr(struct drm_device *dev, struct drm_file *file,
uintptr_t ptr, u32 size, u32 flags, u32 *handle); uintptr_t ptr, u32 size, u32 flags, u32 *handle);
u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu); 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);
void etnaviv_buffer_end(struct etnaviv_gpu *gpu); void etnaviv_buffer_end(struct etnaviv_gpu *gpu);
void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event);
void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event, void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event,
struct etnaviv_cmdbuf *cmdbuf); struct etnaviv_cmdbuf *cmdbuf);
void etnaviv_validate_init(void); void etnaviv_validate_init(void);
......
...@@ -704,25 +704,6 @@ int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file, ...@@ -704,25 +704,6 @@ int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
return ret; return ret;
} }
struct drm_gem_object *etnaviv_gem_new(struct drm_device *dev,
u32 size, u32 flags)
{
struct drm_gem_object *obj;
int ret;
obj = __etnaviv_gem_new(dev, size, flags);
if (IS_ERR(obj))
return obj;
ret = etnaviv_gem_obj_add(dev, obj);
if (ret < 0) {
drm_gem_object_put_unlocked(obj);
return ERR_PTR(ret);
}
return obj;
}
int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags, int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
struct reservation_object *robj, const struct etnaviv_gem_ops *ops, struct reservation_object *robj, const struct etnaviv_gem_ops *ops,
struct etnaviv_gem_object **res) struct etnaviv_gem_object **res)
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "etnaviv_drv.h" #include "etnaviv_drv.h"
#include "etnaviv_gpu.h" #include "etnaviv_gpu.h"
#include "etnaviv_gem.h" #include "etnaviv_gem.h"
#include "etnaviv_perfmon.h"
/* /*
* Cmdstream submission: * Cmdstream submission:
...@@ -283,6 +284,54 @@ static int submit_reloc(struct etnaviv_gem_submit *submit, void *stream, ...@@ -283,6 +284,54 @@ static int submit_reloc(struct etnaviv_gem_submit *submit, void *stream,
return 0; return 0;
} }
static int submit_perfmon_validate(struct etnaviv_gem_submit *submit,
struct etnaviv_cmdbuf *cmdbuf,
const struct drm_etnaviv_gem_submit_pmr *pmrs,
u32 nr_pms)
{
u32 i;
for (i = 0; i < nr_pms; i++) {
const struct drm_etnaviv_gem_submit_pmr *r = pmrs + i;
struct etnaviv_gem_submit_bo *bo;
int ret;
ret = submit_bo(submit, r->read_idx, &bo);
if (ret)
return ret;
/* at offset 0 a sequence number gets stored used for userspace sync */
if (r->read_offset == 0) {
DRM_ERROR("perfmon request: offset is 0");
return -EINVAL;
}
if (r->read_offset >= bo->obj->base.size - sizeof(u32)) {
DRM_ERROR("perfmon request: offset %u outside object", i);
return -EINVAL;
}
if (r->flags & ~(ETNA_PM_PROCESS_PRE | ETNA_PM_PROCESS_POST)) {
DRM_ERROR("perfmon request: flags are not valid");
return -EINVAL;
}
if (etnaviv_pm_req_validate(r, cmdbuf->exec_state)) {
DRM_ERROR("perfmon request: domain or signal not valid");
return -EINVAL;
}
cmdbuf->pmrs[i].flags = r->flags;
cmdbuf->pmrs[i].domain = r->domain;
cmdbuf->pmrs[i].signal = r->signal;
cmdbuf->pmrs[i].sequence = r->sequence;
cmdbuf->pmrs[i].offset = r->read_offset;
cmdbuf->pmrs[i].bo_vma = etnaviv_gem_vmap(&bo->obj->base);
}
return 0;
}
static void submit_cleanup(struct etnaviv_gem_submit *submit) static void submit_cleanup(struct etnaviv_gem_submit *submit)
{ {
unsigned i; unsigned i;
...@@ -306,6 +355,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -306,6 +355,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
struct etnaviv_drm_private *priv = dev->dev_private; struct etnaviv_drm_private *priv = dev->dev_private;
struct drm_etnaviv_gem_submit *args = data; struct drm_etnaviv_gem_submit *args = data;
struct drm_etnaviv_gem_submit_reloc *relocs; struct drm_etnaviv_gem_submit_reloc *relocs;
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_cmdbuf *cmdbuf;
...@@ -347,11 +397,12 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -347,11 +397,12 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
*/ */
bos = kvmalloc_array(args->nr_bos, sizeof(*bos), GFP_KERNEL); bos = kvmalloc_array(args->nr_bos, sizeof(*bos), GFP_KERNEL);
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);
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, cmdbuf = etnaviv_cmdbuf_new(gpu->cmdbuf_suballoc,
ALIGN(args->stream_size, 8) + 8, ALIGN(args->stream_size, 8) + 8,
args->nr_bos); args->nr_bos, args->nr_pmrs);
if (!bos || !relocs || !stream || !cmdbuf) { if (!bos || !relocs || !pmrs || !stream || !cmdbuf) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_submit_cmds; goto err_submit_cmds;
} }
...@@ -373,6 +424,14 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -373,6 +424,14 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
goto err_submit_cmds; goto err_submit_cmds;
} }
ret = copy_from_user(pmrs, u64_to_user_ptr(args->pmrs),
args->nr_pmrs * sizeof(*pmrs));
if (ret) {
ret = -EFAULT;
goto err_submit_cmds;
}
cmdbuf->nr_pmrs = args->nr_pmrs;
ret = copy_from_user(stream, u64_to_user_ptr(args->stream), ret = copy_from_user(stream, u64_to_user_ptr(args->stream),
args->stream_size); args->stream_size);
if (ret) { if (ret) {
...@@ -441,6 +500,10 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -441,6 +500,10 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
if (ret) if (ret)
goto out; goto out;
ret = submit_perfmon_validate(submit, cmdbuf, pmrs, args->nr_pmrs);
if (ret)
goto out;
memcpy(cmdbuf->vaddr, stream, args->stream_size); memcpy(cmdbuf->vaddr, stream, args->stream_size);
cmdbuf->user_size = ALIGN(args->stream_size, 8); cmdbuf->user_size = ALIGN(args->stream_size, 8);
...@@ -496,6 +559,8 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -496,6 +559,8 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
kvfree(bos); kvfree(bos);
if (relocs) if (relocs)
kvfree(relocs); kvfree(relocs);
if (pmrs)
kvfree(pmrs);
return ret; return ret;
} }
This diff is collapsed.
...@@ -88,13 +88,17 @@ struct etnaviv_chip_identity { ...@@ -88,13 +88,17 @@ struct etnaviv_chip_identity {
}; };
struct etnaviv_event { struct etnaviv_event {
bool used;
struct dma_fence *fence; struct dma_fence *fence;
struct etnaviv_cmdbuf *cmdbuf;
void (*sync_point)(struct etnaviv_gpu *gpu, struct etnaviv_event *event);
}; };
struct etnaviv_cmdbuf_suballoc; struct etnaviv_cmdbuf_suballoc;
struct etnaviv_cmdbuf; struct etnaviv_cmdbuf;
#define ETNA_NR_EVENTS 30
struct etnaviv_gpu { struct etnaviv_gpu {
struct drm_device *drm; struct drm_device *drm;
struct thermal_cooling_device *cooling; struct thermal_cooling_device *cooling;
...@@ -112,7 +116,8 @@ struct etnaviv_gpu { ...@@ -112,7 +116,8 @@ struct etnaviv_gpu {
u32 memory_base; u32 memory_base;
/* event management: */ /* event management: */
struct etnaviv_event event[30]; DECLARE_BITMAP(event_bitmap, ETNA_NR_EVENTS);
struct etnaviv_event event[ETNA_NR_EVENTS];
struct completion event_free; struct completion event_free;
spinlock_t event_spinlock; spinlock_t event_spinlock;
...@@ -133,6 +138,10 @@ struct etnaviv_gpu { ...@@ -133,6 +138,10 @@ struct etnaviv_gpu {
/* worker for handling active-list retiring: */ /* worker for handling active-list retiring: */
struct work_struct retire_work; struct work_struct retire_work;
/* worker for handling 'sync' points: */
struct work_struct sync_point_work;
int sync_point_event;
void __iomem *mmio; void __iomem *mmio;
int irq; int irq;
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/iommu.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -31,174 +30,115 @@ ...@@ -31,174 +30,115 @@
#define GPU_MEM_START 0x80000000 #define GPU_MEM_START 0x80000000
struct etnaviv_iommu_domain_pgtable { struct etnaviv_iommuv1_domain {
u32 *pgtable; struct etnaviv_iommu_domain base;
dma_addr_t paddr; u32 *pgtable_cpu;
dma_addr_t pgtable_dma;
}; };
struct etnaviv_iommu_domain { static struct etnaviv_iommuv1_domain *
struct iommu_domain domain; to_etnaviv_domain(struct etnaviv_iommu_domain *domain)
struct device *dev;
void *bad_page_cpu;
dma_addr_t bad_page_dma;
struct etnaviv_iommu_domain_pgtable pgtable;
spinlock_t map_lock;
};
static struct etnaviv_iommu_domain *to_etnaviv_domain(struct iommu_domain *domain)
{
return container_of(domain, struct etnaviv_iommu_domain, domain);
}
static int pgtable_alloc(struct etnaviv_iommu_domain_pgtable *pgtable,
size_t size)
{
pgtable->pgtable = dma_alloc_coherent(NULL, size, &pgtable->paddr, GFP_KERNEL);
if (!pgtable->pgtable)
return -ENOMEM;
return 0;
}
static void pgtable_free(struct etnaviv_iommu_domain_pgtable *pgtable,
size_t size)
{ {
dma_free_coherent(NULL, size, pgtable->pgtable, pgtable->paddr); return container_of(domain, struct etnaviv_iommuv1_domain, base);
}
static u32 pgtable_read(struct etnaviv_iommu_domain_pgtable *pgtable,
unsigned long iova)
{
/* calcuate index into page table */
unsigned int index = (iova - GPU_MEM_START) / SZ_4K;
phys_addr_t paddr;
paddr = pgtable->pgtable[index];
return paddr;
}
static void pgtable_write(struct etnaviv_iommu_domain_pgtable *pgtable,
unsigned long iova, phys_addr_t paddr)
{
/* calcuate index into page table */
unsigned int index = (iova - GPU_MEM_START) / SZ_4K;
pgtable->pgtable[index] = paddr;
} }
static int __etnaviv_iommu_init(struct etnaviv_iommu_domain *etnaviv_domain) static int __etnaviv_iommu_init(struct etnaviv_iommuv1_domain *etnaviv_domain)
{ {
u32 *p; u32 *p;
int ret, i; int i;
etnaviv_domain->bad_page_cpu = dma_alloc_coherent(etnaviv_domain->dev, etnaviv_domain->base.bad_page_cpu = dma_alloc_coherent(
etnaviv_domain->base.dev,
SZ_4K, SZ_4K,
&etnaviv_domain->bad_page_dma, &etnaviv_domain->base.bad_page_dma,
GFP_KERNEL); GFP_KERNEL);
if (!etnaviv_domain->bad_page_cpu) if (!etnaviv_domain->base.bad_page_cpu)
return -ENOMEM; return -ENOMEM;
p = etnaviv_domain->bad_page_cpu; p = etnaviv_domain->base.bad_page_cpu;
for (i = 0; i < SZ_4K / 4; i++) for (i = 0; i < SZ_4K / 4; i++)
*p++ = 0xdead55aa; *p++ = 0xdead55aa;
ret = pgtable_alloc(&etnaviv_domain->pgtable, PT_SIZE); etnaviv_domain->pgtable_cpu =
if (ret < 0) { dma_alloc_coherent(etnaviv_domain->base.dev, PT_SIZE,
dma_free_coherent(etnaviv_domain->dev, SZ_4K, &etnaviv_domain->pgtable_dma,
etnaviv_domain->bad_page_cpu, GFP_KERNEL);
etnaviv_domain->bad_page_dma); if (!etnaviv_domain->pgtable_cpu) {
return ret; dma_free_coherent(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->base.bad_page_cpu,
etnaviv_domain->base.bad_page_dma);
return -ENOMEM;
} }
for (i = 0; i < PT_ENTRIES; i++) for (i = 0; i < PT_ENTRIES; i++)
etnaviv_domain->pgtable.pgtable[i] = etnaviv_domain->pgtable_cpu[i] =
etnaviv_domain->bad_page_dma; etnaviv_domain->base.bad_page_dma;
spin_lock_init(&etnaviv_domain->map_lock);
return 0; return 0;
} }
static void etnaviv_domain_free(struct iommu_domain *domain) static void etnaviv_iommuv1_domain_free(struct etnaviv_iommu_domain *domain)
{ {
struct etnaviv_iommu_domain *etnaviv_domain = to_etnaviv_domain(domain); struct etnaviv_iommuv1_domain *etnaviv_domain =
to_etnaviv_domain(domain);
pgtable_free(&etnaviv_domain->pgtable, PT_SIZE); dma_free_coherent(etnaviv_domain->base.dev, PT_SIZE,
etnaviv_domain->pgtable_cpu,
etnaviv_domain->pgtable_dma);
dma_free_coherent(etnaviv_domain->dev, SZ_4K, dma_free_coherent(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->bad_page_cpu, etnaviv_domain->base.bad_page_cpu,
etnaviv_domain->bad_page_dma); etnaviv_domain->base.bad_page_dma);
kfree(etnaviv_domain); kfree(etnaviv_domain);
} }
static int etnaviv_iommuv1_map(struct iommu_domain *domain, unsigned long iova, static int etnaviv_iommuv1_map(struct etnaviv_iommu_domain *domain,
phys_addr_t paddr, size_t size, int prot) unsigned long iova, phys_addr_t paddr,
size_t size, int prot)
{ {
struct etnaviv_iommu_domain *etnaviv_domain = to_etnaviv_domain(domain); struct etnaviv_iommuv1_domain *etnaviv_domain = to_etnaviv_domain(domain);
unsigned int index = (iova - GPU_MEM_START) / SZ_4K;
if (size != SZ_4K) if (size != SZ_4K)
return -EINVAL; return -EINVAL;
spin_lock(&etnaviv_domain->map_lock); etnaviv_domain->pgtable_cpu[index] = paddr;
pgtable_write(&etnaviv_domain->pgtable, iova, paddr);
spin_unlock(&etnaviv_domain->map_lock);
return 0; return 0;
} }
static size_t etnaviv_iommuv1_unmap(struct iommu_domain *domain, static size_t etnaviv_iommuv1_unmap(struct etnaviv_iommu_domain *domain,
unsigned long iova, size_t size) unsigned long iova, size_t size)
{ {
struct etnaviv_iommu_domain *etnaviv_domain = to_etnaviv_domain(domain); struct etnaviv_iommuv1_domain *etnaviv_domain =
to_etnaviv_domain(domain);
unsigned int index = (iova - GPU_MEM_START) / SZ_4K;
if (size != SZ_4K) if (size != SZ_4K)
return -EINVAL; return -EINVAL;
spin_lock(&etnaviv_domain->map_lock); etnaviv_domain->pgtable_cpu[index] = etnaviv_domain->base.bad_page_dma;
pgtable_write(&etnaviv_domain->pgtable, iova,
etnaviv_domain->bad_page_dma);
spin_unlock(&etnaviv_domain->map_lock);
return SZ_4K; return SZ_4K;
} }
static phys_addr_t etnaviv_iommu_iova_to_phys(struct iommu_domain *domain, static size_t etnaviv_iommuv1_dump_size(struct etnaviv_iommu_domain *domain)
dma_addr_t iova)
{
struct etnaviv_iommu_domain *etnaviv_domain = to_etnaviv_domain(domain);
return pgtable_read(&etnaviv_domain->pgtable, iova);
}
static size_t etnaviv_iommuv1_dump_size(struct iommu_domain *domain)
{ {
return PT_SIZE; return PT_SIZE;
} }
static void etnaviv_iommuv1_dump(struct iommu_domain *domain, void *buf) static void etnaviv_iommuv1_dump(struct etnaviv_iommu_domain *domain, void *buf)
{ {
struct etnaviv_iommu_domain *etnaviv_domain = to_etnaviv_domain(domain); struct etnaviv_iommuv1_domain *etnaviv_domain =
to_etnaviv_domain(domain);
memcpy(buf, etnaviv_domain->pgtable.pgtable, PT_SIZE); memcpy(buf, etnaviv_domain->pgtable_cpu, PT_SIZE);
} }
static const struct etnaviv_iommu_ops etnaviv_iommu_ops = {
.ops = {
.domain_free = etnaviv_domain_free,
.map = etnaviv_iommuv1_map,
.unmap = etnaviv_iommuv1_unmap,
.iova_to_phys = etnaviv_iommu_iova_to_phys,
.pgsize_bitmap = SZ_4K,
},
.dump_size = etnaviv_iommuv1_dump_size,
.dump = etnaviv_iommuv1_dump,
};
void etnaviv_iommuv1_restore(struct etnaviv_gpu *gpu) void etnaviv_iommuv1_restore(struct etnaviv_gpu *gpu)
{ {
struct etnaviv_iommu_domain *etnaviv_domain = struct etnaviv_iommuv1_domain *etnaviv_domain =
to_etnaviv_domain(gpu->mmu->domain); to_etnaviv_domain(gpu->mmu->domain);
u32 pgtable; u32 pgtable;
...@@ -210,7 +150,7 @@ void etnaviv_iommuv1_restore(struct etnaviv_gpu *gpu) ...@@ -210,7 +150,7 @@ void etnaviv_iommuv1_restore(struct etnaviv_gpu *gpu)
gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_PE, gpu->memory_base); gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_PE, gpu->memory_base);
/* set page table address in MC */ /* set page table address in MC */
pgtable = (u32)etnaviv_domain->pgtable.paddr; pgtable = (u32)etnaviv_domain->pgtable_dma;
gpu_write(gpu, VIVS_MC_MMU_FE_PAGE_TABLE, pgtable); gpu_write(gpu, VIVS_MC_MMU_FE_PAGE_TABLE, pgtable);
gpu_write(gpu, VIVS_MC_MMU_TX_PAGE_TABLE, pgtable); gpu_write(gpu, VIVS_MC_MMU_TX_PAGE_TABLE, pgtable);
...@@ -219,28 +159,37 @@ void etnaviv_iommuv1_restore(struct etnaviv_gpu *gpu) ...@@ -219,28 +159,37 @@ void etnaviv_iommuv1_restore(struct etnaviv_gpu *gpu)
gpu_write(gpu, VIVS_MC_MMU_RA_PAGE_TABLE, pgtable); gpu_write(gpu, VIVS_MC_MMU_RA_PAGE_TABLE, pgtable);
} }
struct iommu_domain *etnaviv_iommuv1_domain_alloc(struct etnaviv_gpu *gpu) const struct etnaviv_iommu_domain_ops etnaviv_iommuv1_ops = {
.free = etnaviv_iommuv1_domain_free,
.map = etnaviv_iommuv1_map,
.unmap = etnaviv_iommuv1_unmap,
.dump_size = etnaviv_iommuv1_dump_size,
.dump = etnaviv_iommuv1_dump,
};
struct etnaviv_iommu_domain *
etnaviv_iommuv1_domain_alloc(struct etnaviv_gpu *gpu)
{ {
struct etnaviv_iommu_domain *etnaviv_domain; struct etnaviv_iommuv1_domain *etnaviv_domain;
struct etnaviv_iommu_domain *domain;
int ret; int ret;
etnaviv_domain = kzalloc(sizeof(*etnaviv_domain), GFP_KERNEL); etnaviv_domain = kzalloc(sizeof(*etnaviv_domain), GFP_KERNEL);
if (!etnaviv_domain) if (!etnaviv_domain)
return NULL; return NULL;
etnaviv_domain->dev = gpu->dev; domain = &etnaviv_domain->base;
etnaviv_domain->domain.type = __IOMMU_DOMAIN_PAGING; domain->dev = gpu->dev;
etnaviv_domain->domain.ops = &etnaviv_iommu_ops.ops; domain->base = GPU_MEM_START;
etnaviv_domain->domain.pgsize_bitmap = SZ_4K; domain->size = PT_ENTRIES * SZ_4K;
etnaviv_domain->domain.geometry.aperture_start = GPU_MEM_START; domain->ops = &etnaviv_iommuv1_ops;
etnaviv_domain->domain.geometry.aperture_end = GPU_MEM_START + PT_ENTRIES * SZ_4K - 1;
ret = __etnaviv_iommu_init(etnaviv_domain); ret = __etnaviv_iommu_init(etnaviv_domain);
if (ret) if (ret)
goto out_free; goto out_free;
return &etnaviv_domain->domain; return &etnaviv_domain->base;
out_free: out_free:
kfree(etnaviv_domain); kfree(etnaviv_domain);
......
...@@ -18,11 +18,14 @@ ...@@ -18,11 +18,14 @@
#define __ETNAVIV_IOMMU_H__ #define __ETNAVIV_IOMMU_H__
struct etnaviv_gpu; struct etnaviv_gpu;
struct etnaviv_iommu_domain;
struct iommu_domain *etnaviv_iommuv1_domain_alloc(struct etnaviv_gpu *gpu); struct etnaviv_iommu_domain *
etnaviv_iommuv1_domain_alloc(struct etnaviv_gpu *gpu);
void etnaviv_iommuv1_restore(struct etnaviv_gpu *gpu); void etnaviv_iommuv1_restore(struct etnaviv_gpu *gpu);
struct iommu_domain *etnaviv_iommuv2_domain_alloc(struct etnaviv_gpu *gpu); struct etnaviv_iommu_domain *
etnaviv_iommuv2_domain_alloc(struct etnaviv_gpu *gpu);
void etnaviv_iommuv2_restore(struct etnaviv_gpu *gpu); void etnaviv_iommuv2_restore(struct etnaviv_gpu *gpu);
#endif /* __ETNAVIV_IOMMU_H__ */ #endif /* __ETNAVIV_IOMMU_H__ */
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/iommu.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -40,10 +39,7 @@ ...@@ -40,10 +39,7 @@
#define MMUv2_MAX_STLB_ENTRIES 1024 #define MMUv2_MAX_STLB_ENTRIES 1024
struct etnaviv_iommuv2_domain { struct etnaviv_iommuv2_domain {
struct iommu_domain domain; struct etnaviv_iommu_domain base;
struct device *dev;
void *bad_page_cpu;
dma_addr_t bad_page_dma;
/* M(aster) TLB aka first level pagetable */ /* M(aster) TLB aka first level pagetable */
u32 *mtlb_cpu; u32 *mtlb_cpu;
dma_addr_t mtlb_dma; dma_addr_t mtlb_dma;
...@@ -52,13 +48,15 @@ struct etnaviv_iommuv2_domain { ...@@ -52,13 +48,15 @@ struct etnaviv_iommuv2_domain {
dma_addr_t stlb_dma[1024]; dma_addr_t stlb_dma[1024];
}; };
static struct etnaviv_iommuv2_domain *to_etnaviv_domain(struct iommu_domain *domain) static struct etnaviv_iommuv2_domain *
to_etnaviv_domain(struct etnaviv_iommu_domain *domain)
{ {
return container_of(domain, struct etnaviv_iommuv2_domain, domain); return container_of(domain, struct etnaviv_iommuv2_domain, base);
} }
static int etnaviv_iommuv2_map(struct iommu_domain *domain, unsigned long iova, static int etnaviv_iommuv2_map(struct etnaviv_iommu_domain *domain,
phys_addr_t paddr, size_t size, int prot) unsigned long iova, phys_addr_t paddr,
size_t size, int prot)
{ {
struct etnaviv_iommuv2_domain *etnaviv_domain = struct etnaviv_iommuv2_domain *etnaviv_domain =
to_etnaviv_domain(domain); to_etnaviv_domain(domain);
...@@ -68,7 +66,7 @@ static int etnaviv_iommuv2_map(struct iommu_domain *domain, unsigned long iova, ...@@ -68,7 +66,7 @@ static int etnaviv_iommuv2_map(struct iommu_domain *domain, unsigned long iova,
if (size != SZ_4K) if (size != SZ_4K)
return -EINVAL; return -EINVAL;
if (prot & IOMMU_WRITE) if (prot & ETNAVIV_PROT_WRITE)
entry |= MMUv2_PTE_WRITEABLE; entry |= MMUv2_PTE_WRITEABLE;
mtlb_entry = (iova & MMUv2_MTLB_MASK) >> MMUv2_MTLB_SHIFT; mtlb_entry = (iova & MMUv2_MTLB_MASK) >> MMUv2_MTLB_SHIFT;
...@@ -79,7 +77,7 @@ static int etnaviv_iommuv2_map(struct iommu_domain *domain, unsigned long iova, ...@@ -79,7 +77,7 @@ static int etnaviv_iommuv2_map(struct iommu_domain *domain, unsigned long iova,
return 0; return 0;
} }
static size_t etnaviv_iommuv2_unmap(struct iommu_domain *domain, static size_t etnaviv_iommuv2_unmap(struct etnaviv_iommu_domain *domain,
unsigned long iova, size_t size) unsigned long iova, size_t size)
{ {
struct etnaviv_iommuv2_domain *etnaviv_domain = struct etnaviv_iommuv2_domain *etnaviv_domain =
...@@ -97,38 +95,26 @@ static size_t etnaviv_iommuv2_unmap(struct iommu_domain *domain, ...@@ -97,38 +95,26 @@ static size_t etnaviv_iommuv2_unmap(struct iommu_domain *domain,
return SZ_4K; return SZ_4K;
} }
static phys_addr_t etnaviv_iommuv2_iova_to_phys(struct iommu_domain *domain,
dma_addr_t iova)
{
struct etnaviv_iommuv2_domain *etnaviv_domain =
to_etnaviv_domain(domain);
int mtlb_entry, stlb_entry;
mtlb_entry = (iova & MMUv2_MTLB_MASK) >> MMUv2_MTLB_SHIFT;
stlb_entry = (iova & MMUv2_STLB_MASK) >> MMUv2_STLB_SHIFT;
return etnaviv_domain->stlb_cpu[mtlb_entry][stlb_entry] & ~(SZ_4K - 1);
}
static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain) static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain)
{ {
u32 *p; u32 *p;
int ret, i, j; int ret, i, j;
/* allocate scratch page */ /* allocate scratch page */
etnaviv_domain->bad_page_cpu = dma_alloc_coherent(etnaviv_domain->dev, etnaviv_domain->base.bad_page_cpu = dma_alloc_coherent(
etnaviv_domain->base.dev,
SZ_4K, SZ_4K,
&etnaviv_domain->bad_page_dma, &etnaviv_domain->base.bad_page_dma,
GFP_KERNEL); GFP_KERNEL);
if (!etnaviv_domain->bad_page_cpu) { if (!etnaviv_domain->base.bad_page_cpu) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail_mem; goto fail_mem;
} }
p = etnaviv_domain->bad_page_cpu; p = etnaviv_domain->base.bad_page_cpu;
for (i = 0; i < SZ_4K / 4; i++) for (i = 0; i < SZ_4K / 4; i++)
*p++ = 0xdead55aa; *p++ = 0xdead55aa;
etnaviv_domain->mtlb_cpu = dma_alloc_coherent(etnaviv_domain->dev, etnaviv_domain->mtlb_cpu = dma_alloc_coherent(etnaviv_domain->base.dev,
SZ_4K, SZ_4K,
&etnaviv_domain->mtlb_dma, &etnaviv_domain->mtlb_dma,
GFP_KERNEL); GFP_KERNEL);
...@@ -140,7 +126,7 @@ static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain) ...@@ -140,7 +126,7 @@ static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain)
/* pre-populate STLB pages (may want to switch to on-demand later) */ /* pre-populate STLB pages (may want to switch to on-demand later) */
for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) { for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) {
etnaviv_domain->stlb_cpu[i] = etnaviv_domain->stlb_cpu[i] =
dma_alloc_coherent(etnaviv_domain->dev, dma_alloc_coherent(etnaviv_domain->base.dev,
SZ_4K, SZ_4K,
&etnaviv_domain->stlb_dma[i], &etnaviv_domain->stlb_dma[i],
GFP_KERNEL); GFP_KERNEL);
...@@ -159,19 +145,19 @@ static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain) ...@@ -159,19 +145,19 @@ static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain)
return 0; return 0;
fail_mem: fail_mem:
if (etnaviv_domain->bad_page_cpu) if (etnaviv_domain->base.bad_page_cpu)
dma_free_coherent(etnaviv_domain->dev, SZ_4K, dma_free_coherent(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->bad_page_cpu, etnaviv_domain->base.bad_page_cpu,
etnaviv_domain->bad_page_dma); etnaviv_domain->base.bad_page_dma);
if (etnaviv_domain->mtlb_cpu) if (etnaviv_domain->mtlb_cpu)
dma_free_coherent(etnaviv_domain->dev, SZ_4K, dma_free_coherent(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->mtlb_cpu, etnaviv_domain->mtlb_cpu,
etnaviv_domain->mtlb_dma); etnaviv_domain->mtlb_dma);
for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) { for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) {
if (etnaviv_domain->stlb_cpu[i]) if (etnaviv_domain->stlb_cpu[i])
dma_free_coherent(etnaviv_domain->dev, SZ_4K, dma_free_coherent(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->stlb_cpu[i], etnaviv_domain->stlb_cpu[i],
etnaviv_domain->stlb_dma[i]); etnaviv_domain->stlb_dma[i]);
} }
...@@ -179,23 +165,23 @@ static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain) ...@@ -179,23 +165,23 @@ static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain)
return ret; return ret;
} }
static void etnaviv_iommuv2_domain_free(struct iommu_domain *domain) static void etnaviv_iommuv2_domain_free(struct etnaviv_iommu_domain *domain)
{ {
struct etnaviv_iommuv2_domain *etnaviv_domain = struct etnaviv_iommuv2_domain *etnaviv_domain =
to_etnaviv_domain(domain); to_etnaviv_domain(domain);
int i; int i;
dma_free_coherent(etnaviv_domain->dev, SZ_4K, dma_free_coherent(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->bad_page_cpu, etnaviv_domain->base.bad_page_cpu,
etnaviv_domain->bad_page_dma); etnaviv_domain->base.bad_page_dma);
dma_free_coherent(etnaviv_domain->dev, SZ_4K, dma_free_coherent(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->mtlb_cpu, etnaviv_domain->mtlb_cpu,
etnaviv_domain->mtlb_dma); etnaviv_domain->mtlb_dma);
for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) { for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) {
if (etnaviv_domain->stlb_cpu[i]) if (etnaviv_domain->stlb_cpu[i])
dma_free_coherent(etnaviv_domain->dev, SZ_4K, dma_free_coherent(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->stlb_cpu[i], etnaviv_domain->stlb_cpu[i],
etnaviv_domain->stlb_dma[i]); etnaviv_domain->stlb_dma[i]);
} }
...@@ -203,7 +189,7 @@ static void etnaviv_iommuv2_domain_free(struct iommu_domain *domain) ...@@ -203,7 +189,7 @@ static void etnaviv_iommuv2_domain_free(struct iommu_domain *domain)
vfree(etnaviv_domain); vfree(etnaviv_domain);
} }
static size_t etnaviv_iommuv2_dump_size(struct iommu_domain *domain) static size_t etnaviv_iommuv2_dump_size(struct etnaviv_iommu_domain *domain)
{ {
struct etnaviv_iommuv2_domain *etnaviv_domain = struct etnaviv_iommuv2_domain *etnaviv_domain =
to_etnaviv_domain(domain); to_etnaviv_domain(domain);
...@@ -217,7 +203,7 @@ static size_t etnaviv_iommuv2_dump_size(struct iommu_domain *domain) ...@@ -217,7 +203,7 @@ static size_t etnaviv_iommuv2_dump_size(struct iommu_domain *domain)
return dump_size; return dump_size;
} }
static void etnaviv_iommuv2_dump(struct iommu_domain *domain, void *buf) static void etnaviv_iommuv2_dump(struct etnaviv_iommu_domain *domain, void *buf)
{ {
struct etnaviv_iommuv2_domain *etnaviv_domain = struct etnaviv_iommuv2_domain *etnaviv_domain =
to_etnaviv_domain(domain); to_etnaviv_domain(domain);
...@@ -230,18 +216,6 @@ static void etnaviv_iommuv2_dump(struct iommu_domain *domain, void *buf) ...@@ -230,18 +216,6 @@ static void etnaviv_iommuv2_dump(struct iommu_domain *domain, void *buf)
memcpy(buf, etnaviv_domain->stlb_cpu[i], SZ_4K); memcpy(buf, etnaviv_domain->stlb_cpu[i], SZ_4K);
} }
static const struct etnaviv_iommu_ops etnaviv_iommu_ops = {
.ops = {
.domain_free = etnaviv_iommuv2_domain_free,
.map = etnaviv_iommuv2_map,
.unmap = etnaviv_iommuv2_unmap,
.iova_to_phys = etnaviv_iommuv2_iova_to_phys,
.pgsize_bitmap = SZ_4K,
},
.dump_size = etnaviv_iommuv2_dump_size,
.dump = etnaviv_iommuv2_dump,
};
void etnaviv_iommuv2_restore(struct etnaviv_gpu *gpu) void etnaviv_iommuv2_restore(struct etnaviv_gpu *gpu)
{ {
struct etnaviv_iommuv2_domain *etnaviv_domain = struct etnaviv_iommuv2_domain *etnaviv_domain =
...@@ -254,35 +228,45 @@ void etnaviv_iommuv2_restore(struct etnaviv_gpu *gpu) ...@@ -254,35 +228,45 @@ 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->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);
gpu_write(gpu, VIVS_MMUv2_CONTROL, VIVS_MMUv2_CONTROL_ENABLE); gpu_write(gpu, VIVS_MMUv2_CONTROL, VIVS_MMUv2_CONTROL_ENABLE);
} }
struct iommu_domain *etnaviv_iommuv2_domain_alloc(struct etnaviv_gpu *gpu)
const struct etnaviv_iommu_domain_ops etnaviv_iommuv2_ops = {
.free = etnaviv_iommuv2_domain_free,
.map = etnaviv_iommuv2_map,
.unmap = etnaviv_iommuv2_unmap,
.dump_size = etnaviv_iommuv2_dump_size,
.dump = etnaviv_iommuv2_dump,
};
struct etnaviv_iommu_domain *
etnaviv_iommuv2_domain_alloc(struct etnaviv_gpu *gpu)
{ {
struct etnaviv_iommuv2_domain *etnaviv_domain; struct etnaviv_iommuv2_domain *etnaviv_domain;
struct etnaviv_iommu_domain *domain;
int ret; int ret;
etnaviv_domain = vzalloc(sizeof(*etnaviv_domain)); etnaviv_domain = vzalloc(sizeof(*etnaviv_domain));
if (!etnaviv_domain) if (!etnaviv_domain)
return NULL; return NULL;
etnaviv_domain->dev = gpu->dev; domain = &etnaviv_domain->base;
etnaviv_domain->domain.type = __IOMMU_DOMAIN_PAGING; domain->dev = gpu->dev;
etnaviv_domain->domain.ops = &etnaviv_iommu_ops.ops; domain->base = 0;
etnaviv_domain->domain.pgsize_bitmap = SZ_4K; domain->size = (u64)SZ_1G * 4;
etnaviv_domain->domain.geometry.aperture_start = 0; domain->ops = &etnaviv_iommuv2_ops;
etnaviv_domain->domain.geometry.aperture_end = ~0UL & ~(SZ_4K - 1);
ret = etnaviv_iommuv2_init(etnaviv_domain); ret = etnaviv_iommuv2_init(etnaviv_domain);
if (ret) if (ret)
goto out_free; goto out_free;
return &etnaviv_domain->domain; return &etnaviv_domain->base;
out_free: out_free:
vfree(etnaviv_domain); vfree(etnaviv_domain);
......
...@@ -22,17 +22,64 @@ ...@@ -22,17 +22,64 @@
#include "etnaviv_iommu.h" #include "etnaviv_iommu.h"
#include "etnaviv_mmu.h" #include "etnaviv_mmu.h"
static int etnaviv_fault_handler(struct iommu_domain *iommu, struct device *dev, static void etnaviv_domain_unmap(struct etnaviv_iommu_domain *domain,
unsigned long iova, int flags, void *arg) unsigned long iova, size_t size)
{ {
DBG("*** fault: iova=%08lx, flags=%d", iova, flags); size_t unmapped_page, unmapped = 0;
return 0; size_t pgsize = SZ_4K;
if (!IS_ALIGNED(iova | size, pgsize)) {
pr_err("unaligned: iova 0x%lx size 0x%zx min_pagesz 0x%x\n",
iova, size, pgsize);
return;
}
while (unmapped < size) {
unmapped_page = domain->ops->unmap(domain, iova, pgsize);
if (!unmapped_page)
break;
iova += unmapped_page;
unmapped += unmapped_page;
}
}
static int etnaviv_domain_map(struct etnaviv_iommu_domain *domain,
unsigned long iova, phys_addr_t paddr,
size_t size, int prot)
{
unsigned long orig_iova = iova;
size_t pgsize = SZ_4K;
size_t orig_size = size;
int ret = 0;
if (!IS_ALIGNED(iova | paddr | size, pgsize)) {
pr_err("unaligned: iova 0x%lx pa %pa size 0x%zx min_pagesz 0x%x\n",
iova, &paddr, size, pgsize);
return -EINVAL;
}
while (size) {
ret = domain->ops->map(domain, iova, paddr, pgsize, prot);
if (ret)
break;
iova += pgsize;
paddr += pgsize;
size -= pgsize;
}
/* unroll mapping in case something went wrong */
if (ret)
etnaviv_domain_unmap(domain, orig_iova, orig_size - size);
return ret;
} }
int etnaviv_iommu_map(struct etnaviv_iommu *iommu, u32 iova, static int etnaviv_iommu_map(struct etnaviv_iommu *iommu, u32 iova,
struct sg_table *sgt, unsigned len, int prot) struct sg_table *sgt, unsigned len, int prot)
{ {
struct iommu_domain *domain = iommu->domain; struct etnaviv_iommu_domain *domain = iommu->domain;
struct scatterlist *sg; struct scatterlist *sg;
unsigned int da = iova; unsigned int da = iova;
unsigned int i, j; unsigned int i, j;
...@@ -47,7 +94,7 @@ int etnaviv_iommu_map(struct etnaviv_iommu *iommu, u32 iova, ...@@ -47,7 +94,7 @@ int etnaviv_iommu_map(struct etnaviv_iommu *iommu, u32 iova,
VERB("map[%d]: %08x %08x(%zx)", i, iova, pa, bytes); VERB("map[%d]: %08x %08x(%zx)", i, iova, pa, bytes);
ret = iommu_map(domain, da, pa, bytes, prot); ret = etnaviv_domain_map(domain, da, pa, bytes, prot);
if (ret) if (ret)
goto fail; goto fail;
...@@ -62,27 +109,24 @@ int etnaviv_iommu_map(struct etnaviv_iommu *iommu, u32 iova, ...@@ -62,27 +109,24 @@ int etnaviv_iommu_map(struct etnaviv_iommu *iommu, u32 iova,
for_each_sg(sgt->sgl, sg, i, j) { for_each_sg(sgt->sgl, sg, i, j) {
size_t bytes = sg_dma_len(sg) + sg->offset; size_t bytes = sg_dma_len(sg) + sg->offset;
iommu_unmap(domain, da, bytes); etnaviv_domain_unmap(domain, da, bytes);
da += bytes; da += bytes;
} }
return ret; return ret;
} }
int etnaviv_iommu_unmap(struct etnaviv_iommu *iommu, u32 iova, static void etnaviv_iommu_unmap(struct etnaviv_iommu *iommu, u32 iova,
struct sg_table *sgt, unsigned len) struct sg_table *sgt, unsigned len)
{ {
struct iommu_domain *domain = iommu->domain; struct etnaviv_iommu_domain *domain = iommu->domain;
struct scatterlist *sg; struct scatterlist *sg;
unsigned int da = iova; unsigned int da = iova;
int i; int i;
for_each_sg(sgt->sgl, sg, sgt->nents, i) { for_each_sg(sgt->sgl, sg, sgt->nents, i) {
size_t bytes = sg_dma_len(sg) + sg->offset; size_t bytes = sg_dma_len(sg) + sg->offset;
size_t unmapped;
unmapped = iommu_unmap(domain, da, bytes); etnaviv_domain_unmap(domain, da, bytes);
if (unmapped < bytes)
return unmapped;
VERB("unmap[%d]: %08x(%zx)", i, iova, bytes); VERB("unmap[%d]: %08x(%zx)", i, iova, bytes);
...@@ -90,8 +134,6 @@ int etnaviv_iommu_unmap(struct etnaviv_iommu *iommu, u32 iova, ...@@ -90,8 +134,6 @@ int etnaviv_iommu_unmap(struct etnaviv_iommu *iommu, u32 iova,
da += bytes; da += bytes;
} }
return 0;
} }
static void etnaviv_iommu_remove_mapping(struct etnaviv_iommu *mmu, static void etnaviv_iommu_remove_mapping(struct etnaviv_iommu *mmu,
...@@ -237,7 +279,7 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu, ...@@ -237,7 +279,7 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu,
mmu->last_iova = node->start + etnaviv_obj->base.size; mmu->last_iova = node->start + etnaviv_obj->base.size;
mapping->iova = node->start; mapping->iova = node->start;
ret = etnaviv_iommu_map(mmu, node->start, sgt, etnaviv_obj->base.size, ret = etnaviv_iommu_map(mmu, node->start, sgt, etnaviv_obj->base.size,
IOMMU_READ | IOMMU_WRITE); ETNAVIV_PROT_READ | ETNAVIV_PROT_WRITE);
if (ret < 0) { if (ret < 0) {
drm_mm_remove_node(node); drm_mm_remove_node(node);
...@@ -271,7 +313,7 @@ void etnaviv_iommu_unmap_gem(struct etnaviv_iommu *mmu, ...@@ -271,7 +313,7 @@ void etnaviv_iommu_unmap_gem(struct etnaviv_iommu *mmu,
void etnaviv_iommu_destroy(struct etnaviv_iommu *mmu) void etnaviv_iommu_destroy(struct etnaviv_iommu *mmu)
{ {
drm_mm_takedown(&mmu->mm); drm_mm_takedown(&mmu->mm);
iommu_domain_free(mmu->domain); mmu->domain->ops->free(mmu->domain);
kfree(mmu); kfree(mmu);
} }
...@@ -303,11 +345,7 @@ struct etnaviv_iommu *etnaviv_iommu_new(struct etnaviv_gpu *gpu) ...@@ -303,11 +345,7 @@ struct etnaviv_iommu *etnaviv_iommu_new(struct etnaviv_gpu *gpu)
mutex_init(&mmu->lock); mutex_init(&mmu->lock);
INIT_LIST_HEAD(&mmu->mappings); INIT_LIST_HEAD(&mmu->mappings);
drm_mm_init(&mmu->mm, mmu->domain->geometry.aperture_start, drm_mm_init(&mmu->mm, mmu->domain->base, mmu->domain->size);
mmu->domain->geometry.aperture_end -
mmu->domain->geometry.aperture_start + 1);
iommu_set_fault_handler(mmu->domain, etnaviv_fault_handler, gpu->dev);
return mmu; return mmu;
} }
...@@ -338,8 +376,8 @@ int etnaviv_iommu_get_suballoc_va(struct etnaviv_gpu *gpu, dma_addr_t paddr, ...@@ -338,8 +376,8 @@ int etnaviv_iommu_get_suballoc_va(struct etnaviv_gpu *gpu, dma_addr_t paddr,
mutex_unlock(&mmu->lock); mutex_unlock(&mmu->lock);
return ret; return ret;
} }
ret = iommu_map(mmu->domain, vram_node->start, paddr, size, ret = etnaviv_domain_map(mmu->domain, vram_node->start, paddr,
IOMMU_READ); size, ETNAVIV_PROT_READ);
if (ret < 0) { if (ret < 0) {
drm_mm_remove_node(vram_node); drm_mm_remove_node(vram_node);
mutex_unlock(&mmu->lock); mutex_unlock(&mmu->lock);
...@@ -362,25 +400,17 @@ void etnaviv_iommu_put_suballoc_va(struct etnaviv_gpu *gpu, ...@@ -362,25 +400,17 @@ void etnaviv_iommu_put_suballoc_va(struct etnaviv_gpu *gpu,
if (mmu->version == ETNAVIV_IOMMU_V2) { if (mmu->version == ETNAVIV_IOMMU_V2) {
mutex_lock(&mmu->lock); mutex_lock(&mmu->lock);
iommu_unmap(mmu->domain,iova, size); etnaviv_domain_unmap(mmu->domain, iova, size);
drm_mm_remove_node(vram_node); drm_mm_remove_node(vram_node);
mutex_unlock(&mmu->lock); mutex_unlock(&mmu->lock);
} }
} }
size_t etnaviv_iommu_dump_size(struct etnaviv_iommu *iommu) size_t etnaviv_iommu_dump_size(struct etnaviv_iommu *iommu)
{ {
struct etnaviv_iommu_ops *ops; return iommu->domain->ops->dump_size(iommu->domain);
ops = container_of(iommu->domain->ops, struct etnaviv_iommu_ops, ops);
return ops->dump_size(iommu->domain);
} }
void etnaviv_iommu_dump(struct etnaviv_iommu *iommu, void *buf) void etnaviv_iommu_dump(struct etnaviv_iommu *iommu, void *buf)
{ {
struct etnaviv_iommu_ops *ops; iommu->domain->ops->dump(iommu->domain, buf);
ops = container_of(iommu->domain->ops, struct etnaviv_iommu_ops, ops);
ops->dump(iommu->domain, buf);
} }
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
#ifndef __ETNAVIV_MMU_H__ #ifndef __ETNAVIV_MMU_H__
#define __ETNAVIV_MMU_H__ #define __ETNAVIV_MMU_H__
#include <linux/iommu.h> #define ETNAVIV_PROT_READ (1 << 0)
#define ETNAVIV_PROT_WRITE (1 << 1)
enum etnaviv_iommu_version { enum etnaviv_iommu_version {
ETNAVIV_IOMMU_V1 = 0, ETNAVIV_IOMMU_V1 = 0,
...@@ -26,16 +27,31 @@ enum etnaviv_iommu_version { ...@@ -26,16 +27,31 @@ enum etnaviv_iommu_version {
struct etnaviv_gpu; struct etnaviv_gpu;
struct etnaviv_vram_mapping; struct etnaviv_vram_mapping;
struct etnaviv_iommu_domain;
struct etnaviv_iommu_ops { struct etnaviv_iommu_domain_ops {
struct iommu_ops ops; void (*free)(struct etnaviv_iommu_domain *);
size_t (*dump_size)(struct iommu_domain *); int (*map)(struct etnaviv_iommu_domain *domain, unsigned long iova,
void (*dump)(struct iommu_domain *, void *); phys_addr_t paddr, size_t size, int prot);
size_t (*unmap)(struct etnaviv_iommu_domain *domain, unsigned long iova,
size_t size);
size_t (*dump_size)(struct etnaviv_iommu_domain *);
void (*dump)(struct etnaviv_iommu_domain *, void *);
};
struct etnaviv_iommu_domain {
struct device *dev;
void *bad_page_cpu;
dma_addr_t bad_page_dma;
u64 base;
u64 size;
const struct etnaviv_iommu_domain_ops *ops;
}; };
struct etnaviv_iommu { struct etnaviv_iommu {
struct etnaviv_gpu *gpu; struct etnaviv_gpu *gpu;
struct iommu_domain *domain; struct etnaviv_iommu_domain *domain;
enum etnaviv_iommu_version version; enum etnaviv_iommu_version version;
...@@ -49,18 +65,11 @@ struct etnaviv_iommu { ...@@ -49,18 +65,11 @@ struct etnaviv_iommu {
struct etnaviv_gem_object; struct etnaviv_gem_object;
int etnaviv_iommu_attach(struct etnaviv_iommu *iommu, const char **names,
int cnt);
int etnaviv_iommu_map(struct etnaviv_iommu *iommu, u32 iova,
struct sg_table *sgt, unsigned len, int prot);
int etnaviv_iommu_unmap(struct etnaviv_iommu *iommu, u32 iova,
struct sg_table *sgt, unsigned len);
int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu, int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu,
struct etnaviv_gem_object *etnaviv_obj, u32 memory_base, struct etnaviv_gem_object *etnaviv_obj, u32 memory_base,
struct etnaviv_vram_mapping *mapping); struct etnaviv_vram_mapping *mapping);
void etnaviv_iommu_unmap_gem(struct etnaviv_iommu *mmu, void etnaviv_iommu_unmap_gem(struct etnaviv_iommu *mmu,
struct etnaviv_vram_mapping *mapping); struct etnaviv_vram_mapping *mapping);
void etnaviv_iommu_destroy(struct etnaviv_iommu *iommu);
int etnaviv_iommu_get_suballoc_va(struct etnaviv_gpu *gpu, dma_addr_t paddr, int etnaviv_iommu_get_suballoc_va(struct etnaviv_gpu *gpu, dma_addr_t paddr,
struct drm_mm_node *vram_node, size_t size, struct drm_mm_node *vram_node, size_t size,
...@@ -73,6 +82,7 @@ size_t etnaviv_iommu_dump_size(struct etnaviv_iommu *iommu); ...@@ -73,6 +82,7 @@ size_t etnaviv_iommu_dump_size(struct etnaviv_iommu *iommu);
void etnaviv_iommu_dump(struct etnaviv_iommu *iommu, void *buf); void etnaviv_iommu_dump(struct etnaviv_iommu *iommu, void *buf);
struct etnaviv_iommu *etnaviv_iommu_new(struct etnaviv_gpu *gpu); struct etnaviv_iommu *etnaviv_iommu_new(struct etnaviv_gpu *gpu);
void etnaviv_iommu_destroy(struct etnaviv_iommu *iommu);
void etnaviv_iommu_restore(struct etnaviv_gpu *gpu); void etnaviv_iommu_restore(struct etnaviv_gpu *gpu);
#endif /* __ETNAVIV_MMU_H__ */ #endif /* __ETNAVIV_MMU_H__ */
This diff is collapsed.
/*
* Copyright (C) 2017 Etnaviv Project
* Copyright (C) 2017 Zodiac Inflight Innovations
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ETNAVIV_PERFMON_H__
#define __ETNAVIV_PERFMON_H__
struct etnaviv_gpu;
struct drm_etnaviv_pm_domain;
struct drm_etnaviv_pm_signal;
struct etnaviv_perfmon_request
{
u32 flags;
u8 domain;
u8 signal;
u32 sequence;
/* bo to store a value */
u32 *bo_vma;
u32 offset;
};
int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
struct drm_etnaviv_pm_domain *domain);
int etnaviv_pm_query_sig(struct etnaviv_gpu *gpu,
struct drm_etnaviv_pm_signal *signal);
int etnaviv_pm_req_validate(const struct drm_etnaviv_gem_submit_pmr *r,
u32 exec_state);
void etnaviv_perfmon_process(struct etnaviv_gpu *gpu,
const struct etnaviv_perfmon_request *pmr);
#endif /* __ETNAVIV_PERFMON_H__ */
...@@ -150,6 +150,19 @@ struct drm_etnaviv_gem_submit_bo { ...@@ -150,6 +150,19 @@ struct drm_etnaviv_gem_submit_bo {
__u64 presumed; /* in/out, presumed buffer address */ __u64 presumed; /* in/out, presumed buffer address */
}; };
/* performance monitor request (pmr) */
#define ETNA_PM_PROCESS_PRE 0x0001
#define ETNA_PM_PROCESS_POST 0x0002
struct drm_etnaviv_gem_submit_pmr {
__u32 flags; /* in, when to process request (ETNA_PM_PROCESS_x) */
__u8 domain; /* in, pm domain */
__u8 pad;
__u16 signal; /* in, pm signal */
__u32 sequence; /* in, sequence number */
__u32 read_offset; /* in, offset from read_bo */
__u32 read_idx; /* in, index of read_bo buffer */
};
/* Each cmdstream submit consists of a table of buffers involved, and /* Each cmdstream submit consists of a table of buffers involved, and
* one or more cmdstream buffers. This allows for conditional execution * one or more cmdstream buffers. This allows for conditional execution
* (context-restore), and IB buffers needed for per tile/bin draw cmds. * (context-restore), and IB buffers needed for per tile/bin draw cmds.
...@@ -175,6 +188,9 @@ struct drm_etnaviv_gem_submit { ...@@ -175,6 +188,9 @@ struct drm_etnaviv_gem_submit {
__u64 stream; /* in, ptr to cmdstream */ __u64 stream; /* in, ptr to cmdstream */
__u32 flags; /* in, mask of ETNA_SUBMIT_x */ __u32 flags; /* in, mask of ETNA_SUBMIT_x */
__s32 fence_fd; /* in/out, fence fd (see ETNA_SUBMIT_FENCE_FD_x) */ __s32 fence_fd; /* in/out, fence fd (see ETNA_SUBMIT_FENCE_FD_x) */
__u64 pmrs; /* in, ptr to array of submit_pmr's */
__u32 nr_pmrs; /* in, number of submit_pmr's */
__u32 pad;
}; };
/* The normal way to synchronize with the GPU is just to CPU_PREP on /* The normal way to synchronize with the GPU is just to CPU_PREP on
...@@ -210,6 +226,27 @@ struct drm_etnaviv_gem_wait { ...@@ -210,6 +226,27 @@ struct drm_etnaviv_gem_wait {
struct drm_etnaviv_timespec timeout; /* in */ struct drm_etnaviv_timespec timeout; /* in */
}; };
/*
* Performance Monitor (PM):
*/
struct drm_etnaviv_pm_domain {
__u32 pipe; /* in */
__u8 iter; /* in/out, select pm domain at index iter */
__u8 id; /* out, id of domain */
__u16 nr_signals; /* out, how many signals does this domain provide */
char name[64]; /* out, name of domain */
};
struct drm_etnaviv_pm_signal {
__u32 pipe; /* in */
__u8 domain; /* in, pm domain index */
__u8 pad;
__u16 iter; /* in/out, select pm source at index iter */
__u16 id; /* out, id of signal */
char name[64]; /* out, name of domain */
};
#define DRM_ETNAVIV_GET_PARAM 0x00 #define DRM_ETNAVIV_GET_PARAM 0x00
/* placeholder: /* placeholder:
#define DRM_ETNAVIV_SET_PARAM 0x01 #define DRM_ETNAVIV_SET_PARAM 0x01
...@@ -222,7 +259,9 @@ struct drm_etnaviv_gem_wait { ...@@ -222,7 +259,9 @@ struct drm_etnaviv_gem_wait {
#define DRM_ETNAVIV_WAIT_FENCE 0x07 #define DRM_ETNAVIV_WAIT_FENCE 0x07
#define DRM_ETNAVIV_GEM_USERPTR 0x08 #define DRM_ETNAVIV_GEM_USERPTR 0x08
#define DRM_ETNAVIV_GEM_WAIT 0x09 #define DRM_ETNAVIV_GEM_WAIT 0x09
#define DRM_ETNAVIV_NUM_IOCTLS 0x0a #define DRM_ETNAVIV_PM_QUERY_DOM 0x0a
#define DRM_ETNAVIV_PM_QUERY_SIG 0x0b
#define DRM_ETNAVIV_NUM_IOCTLS 0x0c
#define DRM_IOCTL_ETNAVIV_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GET_PARAM, struct drm_etnaviv_param) #define DRM_IOCTL_ETNAVIV_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GET_PARAM, struct drm_etnaviv_param)
#define DRM_IOCTL_ETNAVIV_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_NEW, struct drm_etnaviv_gem_new) #define DRM_IOCTL_ETNAVIV_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_NEW, struct drm_etnaviv_gem_new)
...@@ -233,6 +272,8 @@ struct drm_etnaviv_gem_wait { ...@@ -233,6 +272,8 @@ struct drm_etnaviv_gem_wait {
#define DRM_IOCTL_ETNAVIV_WAIT_FENCE DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_WAIT_FENCE, struct drm_etnaviv_wait_fence) #define DRM_IOCTL_ETNAVIV_WAIT_FENCE DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_WAIT_FENCE, struct drm_etnaviv_wait_fence)
#define DRM_IOCTL_ETNAVIV_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_USERPTR, struct drm_etnaviv_gem_userptr) #define DRM_IOCTL_ETNAVIV_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_USERPTR, struct drm_etnaviv_gem_userptr)
#define DRM_IOCTL_ETNAVIV_GEM_WAIT DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_WAIT, struct drm_etnaviv_gem_wait) #define DRM_IOCTL_ETNAVIV_GEM_WAIT DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_WAIT, struct drm_etnaviv_gem_wait)
#define DRM_IOCTL_ETNAVIV_PM_QUERY_DOM DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_PM_QUERY_DOM, struct drm_etnaviv_pm_domain)
#define DRM_IOCTL_ETNAVIV_PM_QUERY_SIG DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_PM_QUERY_SIG, struct drm_etnaviv_pm_signal)
#if defined(__cplusplus) #if defined(__cplusplus)
} }
......
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