mirror of https://gitee.com/openkylin/linux.git
drm/etnaviv: move cmdbuf de-/allocation into own file
This will get more complex with the following changes, so move it into its own place. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
This commit is contained in:
parent
d46450737c
commit
ea1f5729aa
|
@ -1,6 +1,7 @@
|
|||
etnaviv-y := \
|
||||
etnaviv_buffer.o \
|
||||
etnaviv_cmd_parser.o \
|
||||
etnaviv_cmdbuf.o \
|
||||
etnaviv_drv.o \
|
||||
etnaviv_dump.o \
|
||||
etnaviv_gem_prime.o \
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "etnaviv_cmdbuf.h"
|
||||
#include "etnaviv_gpu.h"
|
||||
#include "etnaviv_gem.h"
|
||||
#include "etnaviv_mmu.h"
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Etnaviv Project
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "etnaviv_cmdbuf.h"
|
||||
#include "etnaviv_gpu.h"
|
||||
#include "etnaviv_mmu.h"
|
||||
|
||||
struct etnaviv_cmdbuf *etnaviv_cmdbuf_new(struct etnaviv_gpu *gpu, u32 size,
|
||||
size_t nr_bos)
|
||||
{
|
||||
struct etnaviv_cmdbuf *cmdbuf;
|
||||
size_t sz = size_vstruct(nr_bos, sizeof(cmdbuf->bo_map[0]),
|
||||
sizeof(*cmdbuf));
|
||||
|
||||
cmdbuf = kzalloc(sz, GFP_KERNEL);
|
||||
if (!cmdbuf)
|
||||
return NULL;
|
||||
|
||||
if (gpu->mmu->version == ETNAVIV_IOMMU_V2)
|
||||
size = ALIGN(size, SZ_4K);
|
||||
|
||||
cmdbuf->vaddr = dma_alloc_wc(gpu->dev, size, &cmdbuf->paddr,
|
||||
GFP_KERNEL);
|
||||
if (!cmdbuf->vaddr) {
|
||||
kfree(cmdbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cmdbuf->gpu = gpu;
|
||||
cmdbuf->size = size;
|
||||
|
||||
return cmdbuf;
|
||||
}
|
||||
|
||||
void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf)
|
||||
{
|
||||
etnaviv_iommu_put_cmdbuf_va(cmdbuf->gpu, cmdbuf);
|
||||
dma_free_wc(cmdbuf->gpu->dev, cmdbuf->size, cmdbuf->vaddr,
|
||||
cmdbuf->paddr);
|
||||
kfree(cmdbuf);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Etnaviv Project
|
||||
*
|
||||
* 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_CMDBUF_H__
|
||||
#define __ETNAVIV_CMDBUF_H__
|
||||
|
||||
#include <drm/drm_mm.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
struct etnaviv_cmdbuf {
|
||||
/* device this cmdbuf is allocated for */
|
||||
struct etnaviv_gpu *gpu;
|
||||
/* user context key, must be unique between all active users */
|
||||
struct etnaviv_file_private *ctx;
|
||||
/* cmdbuf properties */
|
||||
void *vaddr;
|
||||
dma_addr_t paddr;
|
||||
u32 size;
|
||||
u32 user_size;
|
||||
/* vram node used if the cmdbuf is mapped through the MMUv2 */
|
||||
struct drm_mm_node vram_node;
|
||||
/* fence after which this buffer is to be disposed */
|
||||
struct dma_fence *fence;
|
||||
/* target exec state */
|
||||
u32 exec_state;
|
||||
/* 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];
|
||||
};
|
||||
|
||||
#endif /* __ETNAVIV_CMDBUF_H__ */
|
|
@ -18,6 +18,7 @@
|
|||
#include <linux/of_platform.h>
|
||||
#include <drm/drm_of.h>
|
||||
|
||||
#include "etnaviv_cmdbuf.h"
|
||||
#include "etnaviv_drv.h"
|
||||
#include "etnaviv_gpu.h"
|
||||
#include "etnaviv_gem.h"
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <linux/devcoredump.h>
|
||||
#include "etnaviv_cmdbuf.h"
|
||||
#include "etnaviv_dump.h"
|
||||
#include "etnaviv_gem.h"
|
||||
#include "etnaviv_gpu.h"
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <linux/reservation.h>
|
||||
#include "etnaviv_cmdbuf.h"
|
||||
#include "etnaviv_drv.h"
|
||||
#include "etnaviv_gpu.h"
|
||||
#include "etnaviv_gem.h"
|
||||
|
@ -332,7 +333,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
|
|||
bos = drm_malloc_ab(args->nr_bos, sizeof(*bos));
|
||||
relocs = drm_malloc_ab(args->nr_relocs, sizeof(*relocs));
|
||||
stream = drm_malloc_ab(1, args->stream_size);
|
||||
cmdbuf = etnaviv_gpu_cmdbuf_new(gpu, ALIGN(args->stream_size, 8) + 8,
|
||||
cmdbuf = etnaviv_cmdbuf_new(gpu, ALIGN(args->stream_size, 8) + 8,
|
||||
args->nr_bos);
|
||||
if (!bos || !relocs || !stream || !cmdbuf) {
|
||||
ret = -ENOMEM;
|
||||
|
@ -422,7 +423,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
|
|||
err_submit_cmds:
|
||||
/* if we still own the cmdbuf */
|
||||
if (cmdbuf)
|
||||
etnaviv_gpu_cmdbuf_free(cmdbuf);
|
||||
etnaviv_cmdbuf_free(cmdbuf);
|
||||
if (stream)
|
||||
drm_free_large(stream);
|
||||
if (bos)
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include <linux/dma-fence.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/of_device.h>
|
||||
|
||||
#include "etnaviv_cmdbuf.h"
|
||||
#include "etnaviv_dump.h"
|
||||
#include "etnaviv_gpu.h"
|
||||
#include "etnaviv_gem.h"
|
||||
|
@ -693,7 +695,7 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
|
|||
}
|
||||
|
||||
/* Create buffer: */
|
||||
gpu->buffer = etnaviv_gpu_cmdbuf_new(gpu, PAGE_SIZE, 0);
|
||||
gpu->buffer = etnaviv_cmdbuf_new(gpu, PAGE_SIZE, 0);
|
||||
if (!gpu->buffer) {
|
||||
ret = -ENOMEM;
|
||||
dev_err(gpu->dev, "could not create command buffer\n");
|
||||
|
@ -728,7 +730,7 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
|
|||
return 0;
|
||||
|
||||
free_buffer:
|
||||
etnaviv_gpu_cmdbuf_free(gpu->buffer);
|
||||
etnaviv_cmdbuf_free(gpu->buffer);
|
||||
gpu->buffer = NULL;
|
||||
destroy_iommu:
|
||||
etnaviv_iommu_destroy(gpu->mmu);
|
||||
|
@ -1151,41 +1153,6 @@ static void event_free(struct etnaviv_gpu *gpu, unsigned int event)
|
|||
* Cmdstream submission/retirement:
|
||||
*/
|
||||
|
||||
struct etnaviv_cmdbuf *etnaviv_gpu_cmdbuf_new(struct etnaviv_gpu *gpu, u32 size,
|
||||
size_t nr_bos)
|
||||
{
|
||||
struct etnaviv_cmdbuf *cmdbuf;
|
||||
size_t sz = size_vstruct(nr_bos, sizeof(cmdbuf->bo_map[0]),
|
||||
sizeof(*cmdbuf));
|
||||
|
||||
cmdbuf = kzalloc(sz, GFP_KERNEL);
|
||||
if (!cmdbuf)
|
||||
return NULL;
|
||||
|
||||
if (gpu->mmu->version == ETNAVIV_IOMMU_V2)
|
||||
size = ALIGN(size, SZ_4K);
|
||||
|
||||
cmdbuf->vaddr = dma_alloc_wc(gpu->dev, size, &cmdbuf->paddr,
|
||||
GFP_KERNEL);
|
||||
if (!cmdbuf->vaddr) {
|
||||
kfree(cmdbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cmdbuf->gpu = gpu;
|
||||
cmdbuf->size = size;
|
||||
|
||||
return cmdbuf;
|
||||
}
|
||||
|
||||
void etnaviv_gpu_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf)
|
||||
{
|
||||
etnaviv_iommu_put_cmdbuf_va(cmdbuf->gpu, cmdbuf);
|
||||
dma_free_wc(cmdbuf->gpu->dev, cmdbuf->size, cmdbuf->vaddr,
|
||||
cmdbuf->paddr);
|
||||
kfree(cmdbuf);
|
||||
}
|
||||
|
||||
static void retire_worker(struct work_struct *work)
|
||||
{
|
||||
struct etnaviv_gpu *gpu = container_of(work, struct etnaviv_gpu,
|
||||
|
@ -1211,7 +1178,7 @@ static void retire_worker(struct work_struct *work)
|
|||
etnaviv_gem_mapping_unreference(mapping);
|
||||
}
|
||||
|
||||
etnaviv_gpu_cmdbuf_free(cmdbuf);
|
||||
etnaviv_cmdbuf_free(cmdbuf);
|
||||
/*
|
||||
* We need to balance the runtime PM count caused by
|
||||
* each submission. Upon submission, we increment
|
||||
|
@ -1627,7 +1594,7 @@ static void etnaviv_gpu_unbind(struct device *dev, struct device *master,
|
|||
#endif
|
||||
|
||||
if (gpu->buffer) {
|
||||
etnaviv_gpu_cmdbuf_free(gpu->buffer);
|
||||
etnaviv_cmdbuf_free(gpu->buffer);
|
||||
gpu->buffer = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -150,29 +150,6 @@ struct etnaviv_gpu {
|
|||
struct work_struct recover_work;
|
||||
};
|
||||
|
||||
struct etnaviv_cmdbuf {
|
||||
/* device this cmdbuf is allocated for */
|
||||
struct etnaviv_gpu *gpu;
|
||||
/* user context key, must be unique between all active users */
|
||||
struct etnaviv_file_private *ctx;
|
||||
/* cmdbuf properties */
|
||||
void *vaddr;
|
||||
dma_addr_t paddr;
|
||||
u32 size;
|
||||
u32 user_size;
|
||||
/* vram node used if the cmdbuf is mapped through the MMUv2 */
|
||||
struct drm_mm_node vram_node;
|
||||
/* fence after which this buffer is to be disposed */
|
||||
struct dma_fence *fence;
|
||||
/* target exec state */
|
||||
u32 exec_state;
|
||||
/* 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];
|
||||
};
|
||||
|
||||
static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data)
|
||||
{
|
||||
etnaviv_writel(data, gpu->mmio + reg);
|
||||
|
@ -211,9 +188,9 @@ int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
|
|||
struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout);
|
||||
int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
|
||||
struct etnaviv_gem_submit *submit, struct etnaviv_cmdbuf *cmdbuf);
|
||||
struct etnaviv_cmdbuf *etnaviv_gpu_cmdbuf_new(struct etnaviv_gpu *gpu,
|
||||
struct etnaviv_cmdbuf *etnaviv_cmdbuf_new(struct etnaviv_gpu *gpu,
|
||||
u32 size, size_t nr_bos);
|
||||
void etnaviv_gpu_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf);
|
||||
void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf);
|
||||
int etnaviv_gpu_pm_get_sync(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);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <linux/dma-mapping.h>
|
||||
#include <linux/bitops.h>
|
||||
|
||||
#include "etnaviv_cmdbuf.h"
|
||||
#include "etnaviv_gpu.h"
|
||||
#include "etnaviv_mmu.h"
|
||||
#include "etnaviv_iommu.h"
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include "common.xml.h"
|
||||
#include "etnaviv_cmdbuf.h"
|
||||
#include "etnaviv_drv.h"
|
||||
#include "etnaviv_gem.h"
|
||||
#include "etnaviv_gpu.h"
|
||||
|
|
Loading…
Reference in New Issue