blob: 93e696fcc14f0dc07ef957ceed7a91274ce1fdd0 [file] [log] [blame]
The etnaviv authorsa8c21a52015-12-03 18:21:29 +01001/*
2 * Copyright (C) 2015 Etnaviv Project
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __ETNAVIV_GEM_H__
18#define __ETNAVIV_GEM_H__
19
20#include <linux/reservation.h>
Lucas Stach2f9225d2017-11-24 16:56:37 +010021#include "etnaviv_cmdbuf.h"
The etnaviv authorsa8c21a52015-12-03 18:21:29 +010022#include "etnaviv_drv.h"
23
Lucas Stach6e2b98c2017-03-22 13:00:53 +010024struct dma_fence;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +010025struct etnaviv_gem_ops;
26struct etnaviv_gem_object;
27
28struct etnaviv_gem_userptr {
29 uintptr_t ptr;
Lucas Stachb2295c22017-11-17 14:16:10 +010030 struct mm_struct *mm;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +010031 bool ro;
32};
33
34struct etnaviv_vram_mapping {
35 struct list_head obj_node;
36 struct list_head scan_node;
37 struct list_head mmu_node;
38 struct etnaviv_gem_object *object;
39 struct etnaviv_iommu *mmu;
40 struct drm_mm_node vram_node;
41 unsigned int use;
42 u32 iova;
43};
44
45struct etnaviv_gem_object {
46 struct drm_gem_object base;
47 const struct etnaviv_gem_ops *ops;
48 struct mutex lock;
49
50 u32 flags;
51
52 struct list_head gem_node;
53 struct etnaviv_gpu *gpu; /* non-null if active */
54 atomic_t gpu_active;
55 u32 access;
56
57 struct page **pages;
58 struct sg_table *sgt;
59 void *vaddr;
60
61 /* normally (resv == &_resv) except for imported bo's */
62 struct reservation_object *resv;
63 struct reservation_object _resv;
64
65 struct list_head vram_list;
66
67 /* cache maintenance */
68 u32 last_cpu_prep_op;
69
70 struct etnaviv_gem_userptr userptr;
71};
72
73static inline
74struct etnaviv_gem_object *to_etnaviv_bo(struct drm_gem_object *obj)
75{
76 return container_of(obj, struct etnaviv_gem_object, base);
77}
78
79struct etnaviv_gem_ops {
80 int (*get_pages)(struct etnaviv_gem_object *);
81 void (*release)(struct etnaviv_gem_object *);
Lucas Stacha0a5ab32016-01-25 15:47:28 +010082 void *(*vmap)(struct etnaviv_gem_object *);
Lucas Stacha10e2bde2016-04-27 12:27:02 +020083 int (*mmap)(struct etnaviv_gem_object *, struct vm_area_struct *);
The etnaviv authorsa8c21a52015-12-03 18:21:29 +010084};
85
86static inline bool is_active(struct etnaviv_gem_object *etnaviv_obj)
87{
88 return atomic_read(&etnaviv_obj->gpu_active) != 0;
89}
90
91#define MAX_CMDS 4
92
Russell King8779aa82016-01-21 15:20:55 +000093struct etnaviv_gem_submit_bo {
94 u32 flags;
95 struct etnaviv_gem_object *obj;
96 struct etnaviv_vram_mapping *mapping;
Lucas Stach683da2262017-12-04 19:24:06 +010097 struct dma_fence *excl;
98 unsigned int nr_shared;
99 struct dma_fence **shared;
Russell King8779aa82016-01-21 15:20:55 +0000100};
101
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100102/* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
103 * associated with the cmdstream submission for synchronization (and
Lucas Stachef146c002017-11-24 12:02:38 +0100104 * make it easier to unwind when things go wrong, etc).
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100105 */
106struct etnaviv_gem_submit {
Lucas Stache93b6de2017-12-04 18:41:58 +0100107 struct drm_sched_job sched_job;
Lucas Stache0329e62017-11-24 11:36:03 +0100108 struct kref refcount;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100109 struct etnaviv_gpu *gpu;
Lucas Stach9efabd72017-11-23 18:02:43 +0100110 struct dma_fence *out_fence, *in_fence;
Lucas Stach8bc4d882017-11-29 14:49:04 +0100111 int out_fence_id;
Lucas Stach2f9225d2017-11-24 16:56:37 +0100112 struct list_head node; /* GPU active submit list */
113 struct etnaviv_cmdbuf cmdbuf;
Lucas Stach8bda1512017-11-24 17:56:29 +0100114 bool runtime_resumed;
Lucas Stach797b0152017-11-24 15:16:58 +0100115 u32 exec_state;
Lucas Stachf4a43812017-06-27 16:02:51 +0200116 u32 flags;
Lucas Stachef146c002017-11-24 12:02:38 +0100117 unsigned int nr_pmrs;
118 struct etnaviv_perfmon_request *pmrs;
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100119 unsigned int nr_bos;
Russell King8779aa82016-01-21 15:20:55 +0000120 struct etnaviv_gem_submit_bo bos[0];
Lucas Stachf4a43812017-06-27 16:02:51 +0200121 /* No new members here, the previous one is variable-length! */
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100122};
123
Lucas Stache0329e62017-11-24 11:36:03 +0100124void etnaviv_submit_put(struct etnaviv_gem_submit * submit);
125
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100126int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,
127 struct timespec *timeout);
128int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
129 struct reservation_object *robj, const struct etnaviv_gem_ops *ops,
130 struct etnaviv_gem_object **res);
Lucas Stach54f09282017-11-17 12:17:14 +0100131void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj);
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100132struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj);
133void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj);
134
Russell Kingb6325f42016-01-21 15:20:50 +0000135struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
136 struct drm_gem_object *obj, struct etnaviv_gpu *gpu);
137void etnaviv_gem_mapping_reference(struct etnaviv_vram_mapping *mapping);
138void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping);
139
The etnaviv authorsa8c21a52015-12-03 18:21:29 +0100140#endif /* __ETNAVIV_GEM_H__ */