2018-05-08 14:20:54 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-12-03 17:21:29 +00:00
|
|
|
/*
|
2018-05-08 14:20:54 +00:00
|
|
|
* Copyright (C) 2015-2018 Etnaviv Project
|
2015-12-03 17:21:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/component.h>
|
2019-06-30 05:21:03 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
2019-07-04 10:43:37 +00:00
|
|
|
#include <linux/module.h>
|
2015-12-03 17:21:29 +00:00
|
|
|
#include <linux/of_platform.h>
|
2019-06-30 05:21:03 +00:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
|
|
|
|
#include <drm/drm_debugfs.h>
|
|
|
|
#include <drm/drm_drv.h>
|
|
|
|
#include <drm/drm_file.h>
|
|
|
|
#include <drm/drm_ioctl.h>
|
2016-10-19 10:28:27 +00:00
|
|
|
#include <drm/drm_of.h>
|
2019-06-30 05:21:03 +00:00
|
|
|
#include <drm/drm_prime.h>
|
2015-12-03 17:21:29 +00:00
|
|
|
|
2017-01-16 15:09:51 +00:00
|
|
|
#include "etnaviv_cmdbuf.h"
|
2015-12-03 17:21:29 +00:00
|
|
|
#include "etnaviv_drv.h"
|
|
|
|
#include "etnaviv_gpu.h"
|
|
|
|
#include "etnaviv_gem.h"
|
|
|
|
#include "etnaviv_mmu.h"
|
2017-09-24 13:15:21 +00:00
|
|
|
#include "etnaviv_perfmon.h"
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DRM operations:
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static void load_gpu(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct etnaviv_drm_private *priv = dev->dev_private;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ETNA_MAX_PIPES; i++) {
|
|
|
|
struct etnaviv_gpu *g = priv->gpu[i];
|
|
|
|
|
|
|
|
if (g) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = etnaviv_gpu_init(g);
|
2016-06-17 10:30:50 +00:00
|
|
|
if (ret)
|
2015-12-03 17:21:29 +00:00
|
|
|
priv->gpu[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_open(struct drm_device *dev, struct drm_file *file)
|
|
|
|
{
|
2017-12-04 17:41:58 +00:00
|
|
|
struct etnaviv_drm_private *priv = dev->dev_private;
|
2015-12-03 17:21:29 +00:00
|
|
|
struct etnaviv_file_private *ctx;
|
2019-07-05 17:17:27 +00:00
|
|
|
int ret, i;
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-07-05 17:17:27 +00:00
|
|
|
ctx->mmu = etnaviv_iommu_context_init(priv->mmu_global,
|
|
|
|
priv->cmdbuf_suballoc);
|
|
|
|
if (!ctx->mmu) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2017-12-04 17:41:58 +00:00
|
|
|
for (i = 0; i < ETNA_MAX_PIPES; i++) {
|
|
|
|
struct etnaviv_gpu *gpu = priv->gpu[i];
|
2018-07-13 09:51:14 +00:00
|
|
|
struct drm_sched_rq *rq;
|
2017-12-04 17:41:58 +00:00
|
|
|
|
|
|
|
if (gpu) {
|
2018-07-13 09:51:14 +00:00
|
|
|
rq = &gpu->sched.sched_rq[DRM_SCHED_PRIORITY_NORMAL];
|
|
|
|
drm_sched_entity_init(&ctx->sched_entity[i],
|
|
|
|
&rq, 1, NULL);
|
2017-12-04 17:41:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 17:21:29 +00:00
|
|
|
file->driver_priv = ctx;
|
|
|
|
|
|
|
|
return 0;
|
2019-07-05 17:17:27 +00:00
|
|
|
|
|
|
|
out_free:
|
|
|
|
kfree(ctx);
|
|
|
|
return ret;
|
2015-12-03 17:21:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 14:12:51 +00:00
|
|
|
static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file)
|
2015-12-03 17:21:29 +00:00
|
|
|
{
|
|
|
|
struct etnaviv_drm_private *priv = dev->dev_private;
|
|
|
|
struct etnaviv_file_private *ctx = file->driver_priv;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ETNA_MAX_PIPES; i++) {
|
|
|
|
struct etnaviv_gpu *gpu = priv->gpu[i];
|
|
|
|
|
2018-11-22 14:29:27 +00:00
|
|
|
if (gpu)
|
2018-07-20 12:21:05 +00:00
|
|
|
drm_sched_entity_destroy(&ctx->sched_entity[i]);
|
2015-12-03 17:21:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 17:17:27 +00:00
|
|
|
etnaviv_iommu_context_put(ctx->mmu);
|
|
|
|
|
2015-12-03 17:21:29 +00:00
|
|
|
kfree(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DRM debugfs:
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
static int etnaviv_gem_show(struct drm_device *dev, struct seq_file *m)
|
|
|
|
{
|
|
|
|
struct etnaviv_drm_private *priv = dev->dev_private;
|
|
|
|
|
|
|
|
etnaviv_gem_describe_objects(priv, m);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_mm_show(struct drm_device *dev, struct seq_file *m)
|
|
|
|
{
|
2016-12-29 11:09:24 +00:00
|
|
|
struct drm_printer p = drm_seq_file_printer(m);
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
read_lock(&dev->vma_offset_manager->vm_lock);
|
2016-12-29 11:09:24 +00:00
|
|
|
drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
|
2015-12-03 17:21:29 +00:00
|
|
|
read_unlock(&dev->vma_offset_manager->vm_lock);
|
|
|
|
|
2016-12-29 11:09:24 +00:00
|
|
|
return 0;
|
2015-12-03 17:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_mmu_show(struct etnaviv_gpu *gpu, struct seq_file *m)
|
|
|
|
{
|
2016-12-29 11:09:24 +00:00
|
|
|
struct drm_printer p = drm_seq_file_printer(m);
|
2019-07-05 17:17:27 +00:00
|
|
|
struct etnaviv_iommu_context *mmu_context;
|
2016-12-29 11:09:24 +00:00
|
|
|
|
2015-12-03 17:21:29 +00:00
|
|
|
seq_printf(m, "Active Objects (%s):\n", dev_name(gpu->dev));
|
|
|
|
|
2019-07-05 17:17:27 +00:00
|
|
|
/*
|
|
|
|
* Lock the GPU to avoid a MMU context switch just now and elevate
|
|
|
|
* the refcount of the current context to avoid it disappearing from
|
|
|
|
* under our feet.
|
|
|
|
*/
|
|
|
|
mutex_lock(&gpu->lock);
|
|
|
|
mmu_context = gpu->mmu_context;
|
|
|
|
if (mmu_context)
|
|
|
|
etnaviv_iommu_context_get(mmu_context);
|
|
|
|
mutex_unlock(&gpu->lock);
|
|
|
|
|
|
|
|
if (!mmu_context)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mutex_lock(&mmu_context->lock);
|
|
|
|
drm_mm_print(&mmu_context->mm, &p);
|
|
|
|
mutex_unlock(&mmu_context->lock);
|
|
|
|
|
|
|
|
etnaviv_iommu_context_put(mmu_context);
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void etnaviv_buffer_dump(struct etnaviv_gpu *gpu, struct seq_file *m)
|
|
|
|
{
|
2017-11-24 15:56:37 +00:00
|
|
|
struct etnaviv_cmdbuf *buf = &gpu->buffer;
|
2015-12-03 17:21:29 +00:00
|
|
|
u32 size = buf->size;
|
|
|
|
u32 *ptr = buf->vaddr;
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
seq_printf(m, "virt %p - phys 0x%llx - free 0x%08x\n",
|
2017-01-16 16:00:08 +00:00
|
|
|
buf->vaddr, (u64)etnaviv_cmdbuf_get_pa(buf),
|
|
|
|
size - buf->user_size);
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
for (i = 0; i < size / 4; i++) {
|
|
|
|
if (i && !(i % 4))
|
|
|
|
seq_puts(m, "\n");
|
|
|
|
if (i % 4 == 0)
|
|
|
|
seq_printf(m, "\t0x%p: ", ptr + i);
|
|
|
|
seq_printf(m, "%08x ", *(ptr + i));
|
|
|
|
}
|
|
|
|
seq_puts(m, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_ring_show(struct etnaviv_gpu *gpu, struct seq_file *m)
|
|
|
|
{
|
|
|
|
seq_printf(m, "Ring Buffer (%s): ", dev_name(gpu->dev));
|
|
|
|
|
|
|
|
mutex_lock(&gpu->lock);
|
|
|
|
etnaviv_buffer_dump(gpu, m);
|
|
|
|
mutex_unlock(&gpu->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int show_unlocked(struct seq_file *m, void *arg)
|
|
|
|
{
|
|
|
|
struct drm_info_node *node = (struct drm_info_node *) m->private;
|
|
|
|
struct drm_device *dev = node->minor->dev;
|
|
|
|
int (*show)(struct drm_device *dev, struct seq_file *m) =
|
|
|
|
node->info_ent->data;
|
|
|
|
|
|
|
|
return show(dev, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int show_each_gpu(struct seq_file *m, void *arg)
|
|
|
|
{
|
|
|
|
struct drm_info_node *node = (struct drm_info_node *) m->private;
|
|
|
|
struct drm_device *dev = node->minor->dev;
|
|
|
|
struct etnaviv_drm_private *priv = dev->dev_private;
|
|
|
|
struct etnaviv_gpu *gpu;
|
|
|
|
int (*show)(struct etnaviv_gpu *gpu, struct seq_file *m) =
|
|
|
|
node->info_ent->data;
|
|
|
|
unsigned int i;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < ETNA_MAX_PIPES; i++) {
|
|
|
|
gpu = priv->gpu[i];
|
|
|
|
if (!gpu)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = show(gpu, m);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct drm_info_list etnaviv_debugfs_list[] = {
|
|
|
|
{"gpu", show_each_gpu, 0, etnaviv_gpu_debugfs},
|
|
|
|
{"gem", show_unlocked, 0, etnaviv_gem_show},
|
|
|
|
{ "mm", show_unlocked, 0, etnaviv_mm_show },
|
|
|
|
{"mmu", show_each_gpu, 0, etnaviv_mmu_show},
|
|
|
|
{"ring", show_each_gpu, 0, etnaviv_ring_show},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int etnaviv_debugfs_init(struct drm_minor *minor)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = minor->dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_debugfs_create_files(etnaviv_debugfs_list,
|
|
|
|
ARRAY_SIZE(etnaviv_debugfs_list),
|
|
|
|
minor->debugfs_root, minor);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev->dev, "could not install etnaviv_debugfs_list\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DRM ioctls:
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int etnaviv_ioctl_get_param(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct etnaviv_drm_private *priv = dev->dev_private;
|
|
|
|
struct drm_etnaviv_param *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_gpu_get_param(gpu, args->param, &args->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_ioctl_gem_new(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_etnaviv_gem_new *args = data;
|
|
|
|
|
|
|
|
if (args->flags & ~(ETNA_BO_CACHED | ETNA_BO_WC | ETNA_BO_UNCACHED |
|
|
|
|
ETNA_BO_FORCE_MMU))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return etnaviv_gem_new_handle(dev, file, args->size,
|
|
|
|
args->flags, &args->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TS(t) ((struct timespec){ \
|
|
|
|
.tv_sec = (t).tv_sec, \
|
|
|
|
.tv_nsec = (t).tv_nsec \
|
|
|
|
})
|
|
|
|
|
|
|
|
static int etnaviv_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_etnaviv_gem_cpu_prep *args = data;
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (args->op & ~(ETNA_PREP_READ | ETNA_PREP_WRITE | ETNA_PREP_NOSYNC))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-05-09 10:04:54 +00:00
|
|
|
obj = drm_gem_object_lookup(file, args->handle);
|
2015-12-03 17:21:29 +00:00
|
|
|
if (!obj)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
ret = etnaviv_gem_cpu_prep(obj, args->op, &TS(args->timeout));
|
|
|
|
|
2017-08-03 11:58:23 +00:00
|
|
|
drm_gem_object_put_unlocked(obj);
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_ioctl_gem_cpu_fini(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_etnaviv_gem_cpu_fini *args = data;
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (args->flags)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-05-09 10:04:54 +00:00
|
|
|
obj = drm_gem_object_lookup(file, args->handle);
|
2015-12-03 17:21:29 +00:00
|
|
|
if (!obj)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
ret = etnaviv_gem_cpu_fini(obj);
|
|
|
|
|
2017-08-03 11:58:23 +00:00
|
|
|
drm_gem_object_put_unlocked(obj);
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_ioctl_gem_info(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_etnaviv_gem_info *args = data;
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (args->pad)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-05-09 10:04:54 +00:00
|
|
|
obj = drm_gem_object_lookup(file, args->handle);
|
2015-12-03 17:21:29 +00:00
|
|
|
if (!obj)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
ret = etnaviv_gem_mmap_offset(obj, &args->offset);
|
2017-08-03 11:58:23 +00:00
|
|
|
drm_gem_object_put_unlocked(obj);
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_ioctl_wait_fence(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_etnaviv_wait_fence *args = data;
|
|
|
|
struct etnaviv_drm_private *priv = dev->dev_private;
|
|
|
|
struct timespec *timeout = &TS(args->timeout);
|
|
|
|
struct etnaviv_gpu *gpu;
|
|
|
|
|
|
|
|
if (args->flags & ~(ETNA_WAIT_NONBLOCK))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (args->pipe >= ETNA_MAX_PIPES)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
gpu = priv->gpu[args->pipe];
|
|
|
|
if (!gpu)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
if (args->flags & ETNA_WAIT_NONBLOCK)
|
|
|
|
timeout = NULL;
|
|
|
|
|
|
|
|
return etnaviv_gpu_wait_fence_interruptible(gpu, args->fence,
|
|
|
|
timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_ioctl_gem_userptr(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_etnaviv_gem_userptr *args = data;
|
|
|
|
|
|
|
|
if (args->flags & ~(ETNA_USERPTR_READ|ETNA_USERPTR_WRITE) ||
|
|
|
|
args->flags == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (offset_in_page(args->user_ptr | args->user_size) ||
|
|
|
|
(uintptr_t)args->user_ptr != args->user_ptr ||
|
|
|
|
(u32)args->user_size != args->user_size ||
|
|
|
|
args->user_ptr & ~PAGE_MASK)
|
|
|
|
return -EINVAL;
|
|
|
|
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 02:57:57 +00:00
|
|
|
if (!access_ok((void __user *)(unsigned long)args->user_ptr,
|
2015-12-03 17:21:29 +00:00
|
|
|
args->user_size))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return etnaviv_gem_new_userptr(dev, file, args->user_ptr,
|
|
|
|
args->user_size, args->flags,
|
|
|
|
&args->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_ioctl_gem_wait(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct etnaviv_drm_private *priv = dev->dev_private;
|
|
|
|
struct drm_etnaviv_gem_wait *args = data;
|
|
|
|
struct timespec *timeout = &TS(args->timeout);
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
struct etnaviv_gpu *gpu;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (args->flags & ~(ETNA_WAIT_NONBLOCK))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (args->pipe >= ETNA_MAX_PIPES)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
gpu = priv->gpu[args->pipe];
|
|
|
|
if (!gpu)
|
|
|
|
return -ENXIO;
|
|
|
|
|
2016-05-09 10:04:54 +00:00
|
|
|
obj = drm_gem_object_lookup(file, args->handle);
|
2015-12-03 17:21:29 +00:00
|
|
|
if (!obj)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
if (args->flags & ETNA_WAIT_NONBLOCK)
|
|
|
|
timeout = NULL;
|
|
|
|
|
|
|
|
ret = etnaviv_gem_wait_bo(gpu, obj, timeout);
|
|
|
|
|
2017-08-03 11:58:23 +00:00
|
|
|
drm_gem_object_put_unlocked(obj);
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-24 13:15:21 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-12-03 17:21:29 +00:00
|
|
|
static const struct drm_ioctl_desc etnaviv_ioctls[] = {
|
|
|
|
#define ETNA_IOCTL(n, func, flags) \
|
|
|
|
DRM_IOCTL_DEF_DRV(ETNAVIV_##n, etnaviv_ioctl_##func, flags)
|
2019-05-27 08:17:31 +00:00
|
|
|
ETNA_IOCTL(GET_PARAM, get_param, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(GEM_NEW, gem_new, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(GEM_INFO, gem_info, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(GEM_CPU_PREP, gem_cpu_prep, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(GEM_CPU_FINI, gem_cpu_fini, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(GEM_SUBMIT, gem_submit, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(WAIT_FENCE, wait_fence, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(GEM_USERPTR, gem_userptr, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(GEM_WAIT, gem_wait, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(PM_QUERY_DOM, pm_query_dom, DRM_RENDER_ALLOW),
|
|
|
|
ETNA_IOCTL(PM_QUERY_SIG, pm_query_sig, DRM_RENDER_ALLOW),
|
2015-12-03 17:21:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct vm_operations_struct vm_ops = {
|
|
|
|
.fault = etnaviv_gem_fault,
|
|
|
|
.open = drm_gem_vm_open,
|
|
|
|
.close = drm_gem_vm_close,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = drm_open,
|
|
|
|
.release = drm_release,
|
|
|
|
.unlocked_ioctl = drm_ioctl,
|
|
|
|
.compat_ioctl = drm_compat_ioctl,
|
|
|
|
.poll = drm_poll,
|
|
|
|
.read = drm_read,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.mmap = etnaviv_gem_mmap,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct drm_driver etnaviv_drm_driver = {
|
2019-06-17 15:39:24 +00:00
|
|
|
.driver_features = DRIVER_GEM | DRIVER_RENDER,
|
2015-12-03 17:21:29 +00:00
|
|
|
.open = etnaviv_open,
|
2017-03-08 14:12:51 +00:00
|
|
|
.postclose = etnaviv_postclose,
|
2016-04-26 17:29:49 +00:00
|
|
|
.gem_free_object_unlocked = etnaviv_gem_free_object,
|
2015-12-03 17:21:29 +00:00
|
|
|
.gem_vm_ops = &vm_ops,
|
|
|
|
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
|
|
|
|
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
|
|
|
|
.gem_prime_pin = etnaviv_gem_prime_pin,
|
|
|
|
.gem_prime_unpin = etnaviv_gem_prime_unpin,
|
|
|
|
.gem_prime_get_sg_table = etnaviv_gem_prime_get_sg_table,
|
|
|
|
.gem_prime_import_sg_table = etnaviv_gem_prime_import_sg_table,
|
|
|
|
.gem_prime_vmap = etnaviv_gem_prime_vmap,
|
|
|
|
.gem_prime_vunmap = etnaviv_gem_prime_vunmap,
|
2016-11-18 14:15:16 +00:00
|
|
|
.gem_prime_mmap = etnaviv_gem_prime_mmap,
|
2015-12-03 17:21:29 +00:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
.debugfs_init = etnaviv_debugfs_init,
|
|
|
|
#endif
|
|
|
|
.ioctls = etnaviv_ioctls,
|
|
|
|
.num_ioctls = DRM_ETNAVIV_NUM_IOCTLS,
|
|
|
|
.fops = &fops,
|
|
|
|
.name = "etnaviv",
|
|
|
|
.desc = "etnaviv DRM",
|
|
|
|
.date = "20151214",
|
|
|
|
.major = 1,
|
2019-08-02 12:27:33 +00:00
|
|
|
.minor = 3,
|
2015-12-03 17:21:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Platform driver:
|
|
|
|
*/
|
|
|
|
static int etnaviv_bind(struct device *dev)
|
|
|
|
{
|
|
|
|
struct etnaviv_drm_private *priv;
|
|
|
|
struct drm_device *drm;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
drm = drm_dev_alloc(&etnaviv_drm_driver, dev);
|
2016-09-21 14:59:19 +00:00
|
|
|
if (IS_ERR(drm))
|
|
|
|
return PTR_ERR(drm);
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv) {
|
|
|
|
dev_err(dev, "failed to allocate private data\n");
|
|
|
|
ret = -ENOMEM;
|
2018-09-26 11:41:39 +00:00
|
|
|
goto out_put;
|
2015-12-03 17:21:29 +00:00
|
|
|
}
|
|
|
|
drm->dev_private = priv;
|
|
|
|
|
2019-02-25 10:51:30 +00:00
|
|
|
dev->dma_parms = &priv->dma_parms;
|
|
|
|
dma_set_max_seg_size(dev, SZ_2G);
|
|
|
|
|
2015-12-03 17:21:29 +00:00
|
|
|
mutex_init(&priv->gem_lock);
|
|
|
|
INIT_LIST_HEAD(&priv->gem_list);
|
|
|
|
priv->num_gpus = 0;
|
|
|
|
|
2019-07-05 17:17:22 +00:00
|
|
|
priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(drm->dev);
|
|
|
|
if (IS_ERR(priv->cmdbuf_suballoc)) {
|
|
|
|
dev_err(drm->dev, "Failed to create cmdbuf suballocator\n");
|
|
|
|
ret = PTR_ERR(priv->cmdbuf_suballoc);
|
|
|
|
goto out_free_priv;
|
|
|
|
}
|
|
|
|
|
2015-12-03 17:21:29 +00:00
|
|
|
dev_set_drvdata(dev, drm);
|
|
|
|
|
|
|
|
ret = component_bind_all(dev, drm);
|
|
|
|
if (ret < 0)
|
2019-07-05 17:17:22 +00:00
|
|
|
goto out_destroy_suballoc;
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
load_gpu(drm);
|
|
|
|
|
|
|
|
ret = drm_dev_register(drm, 0);
|
|
|
|
if (ret)
|
2019-07-05 17:17:22 +00:00
|
|
|
goto out_unbind;
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2019-07-05 17:17:22 +00:00
|
|
|
out_unbind:
|
2015-12-03 17:21:29 +00:00
|
|
|
component_unbind_all(dev, drm);
|
2019-07-05 17:17:22 +00:00
|
|
|
out_destroy_suballoc:
|
|
|
|
etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc);
|
|
|
|
out_free_priv:
|
2015-12-03 17:21:29 +00:00
|
|
|
kfree(priv);
|
2018-09-26 11:41:39 +00:00
|
|
|
out_put:
|
|
|
|
drm_dev_put(drm);
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void etnaviv_unbind(struct device *dev)
|
|
|
|
{
|
|
|
|
struct drm_device *drm = dev_get_drvdata(dev);
|
|
|
|
struct etnaviv_drm_private *priv = drm->dev_private;
|
|
|
|
|
|
|
|
drm_dev_unregister(drm);
|
|
|
|
|
|
|
|
component_unbind_all(dev, drm);
|
|
|
|
|
2019-02-25 10:51:30 +00:00
|
|
|
dev->dma_parms = NULL;
|
|
|
|
|
2019-07-05 17:17:22 +00:00
|
|
|
etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc);
|
|
|
|
|
2015-12-03 17:21:29 +00:00
|
|
|
drm->dev_private = NULL;
|
|
|
|
kfree(priv);
|
|
|
|
|
2018-09-26 11:41:39 +00:00
|
|
|
drm_dev_put(drm);
|
2015-12-03 17:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct component_master_ops etnaviv_master_ops = {
|
|
|
|
.bind = etnaviv_bind,
|
|
|
|
.unbind = etnaviv_unbind,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int compare_of(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
struct device_node *np = data;
|
|
|
|
|
|
|
|
return dev->of_node == np;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compare_str(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
return !strcmp(dev_name(dev), data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_pdev_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct component_match *match = NULL;
|
|
|
|
|
2018-01-24 14:30:29 +00:00
|
|
|
if (!dev->platform_data) {
|
2015-12-03 17:21:29 +00:00
|
|
|
struct device_node *core_node;
|
|
|
|
|
2018-01-24 14:30:29 +00:00
|
|
|
for_each_compatible_node(core_node, NULL, "vivante,gc") {
|
|
|
|
if (!of_device_is_available(core_node))
|
|
|
|
continue;
|
2015-12-03 17:21:29 +00:00
|
|
|
|
2016-10-19 10:28:27 +00:00
|
|
|
drm_of_component_match_add(&pdev->dev, &match,
|
|
|
|
compare_of, core_node);
|
2015-12-03 17:21:29 +00:00
|
|
|
}
|
2018-01-24 14:30:29 +00:00
|
|
|
} else {
|
2015-12-03 17:21:29 +00:00
|
|
|
char **names = dev->platform_data;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; names[i]; i++)
|
|
|
|
component_match_add(dev, &match, compare_str, names[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return component_master_add_with_match(dev, &etnaviv_master_ops, match);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etnaviv_pdev_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
component_master_del(&pdev->dev, &etnaviv_master_ops);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver etnaviv_platform_driver = {
|
|
|
|
.probe = etnaviv_pdev_probe,
|
|
|
|
.remove = etnaviv_pdev_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "etnaviv",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-06-27 13:07:45 +00:00
|
|
|
static struct platform_device *etnaviv_drm;
|
|
|
|
|
2015-12-03 17:21:29 +00:00
|
|
|
static int __init etnaviv_init(void)
|
|
|
|
{
|
2018-06-27 13:07:45 +00:00
|
|
|
struct platform_device *pdev;
|
2015-12-03 17:21:29 +00:00
|
|
|
int ret;
|
2018-01-24 14:30:29 +00:00
|
|
|
struct device_node *np;
|
2015-12-03 17:21:29 +00:00
|
|
|
|
|
|
|
etnaviv_validate_init();
|
|
|
|
|
|
|
|
ret = platform_driver_register(&etnaviv_gpu_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = platform_driver_register(&etnaviv_platform_driver);
|
|
|
|
if (ret != 0)
|
2018-06-27 13:07:45 +00:00
|
|
|
goto unregister_gpu_driver;
|
2015-12-03 17:21:29 +00:00
|
|
|
|
2018-01-24 14:30:29 +00:00
|
|
|
/*
|
|
|
|
* If the DT contains at least one available GPU device, instantiate
|
|
|
|
* the DRM platform device.
|
|
|
|
*/
|
|
|
|
for_each_compatible_node(np, NULL, "vivante,gc") {
|
|
|
|
if (!of_device_is_available(np))
|
|
|
|
continue;
|
2018-09-12 14:34:27 +00:00
|
|
|
|
|
|
|
pdev = platform_device_alloc("etnaviv", -1);
|
|
|
|
if (!pdev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
of_node_put(np);
|
|
|
|
goto unregister_platform_driver;
|
|
|
|
}
|
|
|
|
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(40);
|
|
|
|
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply the same DMA configuration to the virtual etnaviv
|
|
|
|
* device as the GPU we found. This assumes that all Vivante
|
|
|
|
* GPUs in the system share the same DMA constraints.
|
|
|
|
*/
|
|
|
|
of_dma_configure(&pdev->dev, np, true);
|
|
|
|
|
|
|
|
ret = platform_device_add(pdev);
|
|
|
|
if (ret) {
|
|
|
|
platform_device_put(pdev);
|
2018-06-27 13:07:45 +00:00
|
|
|
of_node_put(np);
|
|
|
|
goto unregister_platform_driver;
|
|
|
|
}
|
2018-09-12 14:34:27 +00:00
|
|
|
|
2018-06-27 13:07:45 +00:00
|
|
|
etnaviv_drm = pdev;
|
2018-01-24 14:30:29 +00:00
|
|
|
of_node_put(np);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-06-27 13:07:45 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
unregister_platform_driver:
|
|
|
|
platform_driver_unregister(&etnaviv_platform_driver);
|
|
|
|
unregister_gpu_driver:
|
|
|
|
platform_driver_unregister(&etnaviv_gpu_driver);
|
2015-12-03 17:21:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
module_init(etnaviv_init);
|
|
|
|
|
|
|
|
static void __exit etnaviv_exit(void)
|
|
|
|
{
|
2018-06-27 13:07:46 +00:00
|
|
|
platform_device_unregister(etnaviv_drm);
|
2015-12-03 17:21:29 +00:00
|
|
|
platform_driver_unregister(&etnaviv_platform_driver);
|
2018-06-27 13:07:46 +00:00
|
|
|
platform_driver_unregister(&etnaviv_gpu_driver);
|
2015-12-03 17:21:29 +00:00
|
|
|
}
|
|
|
|
module_exit(etnaviv_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Christian Gmeiner <christian.gmeiner@gmail.com>");
|
|
|
|
MODULE_AUTHOR("Russell King <rmk+kernel@arm.linux.org.uk>");
|
|
|
|
MODULE_AUTHOR("Lucas Stach <l.stach@pengutronix.de>");
|
|
|
|
MODULE_DESCRIPTION("etnaviv DRM Driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_ALIAS("platform:etnaviv");
|