etnaviv_drv.h 4.2 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2
/*
3
 * Copyright (C) 2015-2018 Etnaviv Project
4 5 6 7 8
 */

#ifndef __ETNAVIV_DRV_H__
#define __ETNAVIV_DRV_H__

S
Sam Ravnborg 已提交
9 10 11
#include <linux/list.h>
#include <linux/mm_types.h>
#include <linux/sizes.h>
12
#include <linux/time64.h>
13 14 15 16 17
#include <linux/types.h>

#include <drm/drm_fb_helper.h>
#include <drm/drm_gem.h>
#include <drm/etnaviv_drm.h>
18
#include <drm/gpu_scheduler.h>
19 20 21 22 23 24

struct etnaviv_cmdbuf;
struct etnaviv_gpu;
struct etnaviv_mmu;
struct etnaviv_gem_object;
struct etnaviv_gem_submit;
L
Lucas Stach 已提交
25
struct etnaviv_iommu_global;
26

L
Lucas Stach 已提交
27 28
#define ETNAVIV_SOFTPIN_START_ADDRESS	SZ_4M /* must be >= SUBALLOC_SIZE */

29
struct etnaviv_file_private {
30
	struct etnaviv_iommu_context	*mmu;
31
	struct drm_sched_entity		sched_entity[ETNA_MAX_PIPES];
32 33 34 35
};

struct etnaviv_drm_private {
	int num_gpus;
36
	struct device_dma_parameters dma_parms;
37
	struct etnaviv_gpu *gpu[ETNA_MAX_PIPES];
38
	gfp_t shm_gfp_mask;
39

40
	struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc;
L
Lucas Stach 已提交
41
	struct etnaviv_iommu_global *mmu_global;
42

43 44 45 46 47 48 49 50 51 52 53 54 55
	/* list of GEM objects: */
	struct mutex gem_lock;
	struct list_head gem_list;
};

int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
		struct drm_file *file);

int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma);
int etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset);
struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj);
void *etnaviv_gem_prime_vmap(struct drm_gem_object *obj);
void etnaviv_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
L
Lucas Stach 已提交
56 57
int etnaviv_gem_prime_mmap(struct drm_gem_object *obj,
			   struct vm_area_struct *vma);
58 59 60 61
struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev,
	struct dma_buf_attachment *attach, struct sg_table *sg);
int etnaviv_gem_prime_pin(struct drm_gem_object *obj);
void etnaviv_gem_prime_unpin(struct drm_gem_object *obj);
62
void *etnaviv_gem_vmap(struct drm_gem_object *obj);
63
int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
64
		struct drm_etnaviv_timespec *timeout);
65 66 67 68 69 70 71
int etnaviv_gem_cpu_fini(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,
		u32 size, u32 flags, u32 *handle);
int etnaviv_gem_new_userptr(struct drm_device *dev, struct drm_file *file,
	uintptr_t ptr, u32 size, u32 flags, u32 *handle);
u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu);
72
u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe_addr);
L
Lucas Stach 已提交
73
u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu, unsigned short id);
74
void etnaviv_buffer_end(struct etnaviv_gpu *gpu);
75
void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event);
76
void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,
77
	struct etnaviv_iommu_context *mmu,
78
	unsigned int event, struct etnaviv_cmdbuf *cmdbuf);
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
void etnaviv_validate_init(void);
bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu,
	u32 *stream, unsigned int size,
	struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size);

#ifdef CONFIG_DEBUG_FS
void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv,
	struct seq_file *m);
#endif

#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)

/*
 * Return the storage size of a structure with a variable length array.
 * The array is nelem elements of elem_size, where the base structure
 * is defined by base.  If the size overflows size_t, return zero.
 */
static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
{
	if (elem_size && nelem > (SIZE_MAX - base) / elem_size)
		return 0;
	return base + nelem * elem_size;
}

104 105 106 107 108
/*
 * Etnaviv timeouts are specified wrt CLOCK_MONOTONIC, not jiffies.
 * We need to calculate the timeout in terms of number of jiffies
 * between the specified timeout and the current CLOCK_MONOTONIC time.
 */
109
static inline unsigned long etnaviv_timeout_to_jiffies(
110
	const struct drm_etnaviv_timespec *timeout)
111
{
112 113 114 115
	struct timespec64 ts, to = {
		.tv_sec = timeout->tv_sec,
		.tv_nsec = timeout->tv_nsec,
	};
116 117 118 119 120 121

	ktime_get_ts64(&ts);

	/* timeouts before "now" have already expired */
	if (timespec64_compare(&to, &ts) <= 0)
		return 0;
122

123
	ts = timespec64_sub(to, ts);
124

125
	return timespec64_to_jiffies(&ts);
126 127 128
}

#endif /* __ETNAVIV_DRV_H__ */