Commit | Line | Data |
---|---|---|
a8c21a54 T |
1 | /* |
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> | |
2f9225db | 21 | #include "etnaviv_cmdbuf.h" |
a8c21a54 T |
22 | #include "etnaviv_drv.h" |
23 | ||
6e2b98cf | 24 | struct dma_fence; |
a8c21a54 T |
25 | struct etnaviv_gem_ops; |
26 | struct etnaviv_gem_object; | |
27 | ||
28 | struct etnaviv_gem_userptr { | |
29 | uintptr_t ptr; | |
b2295c24 | 30 | struct mm_struct *mm; |
a8c21a54 T |
31 | bool ro; |
32 | }; | |
33 | ||
34 | struct 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 | ||
45 | struct 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 | ||
73 | static inline | |
74 | struct etnaviv_gem_object *to_etnaviv_bo(struct drm_gem_object *obj) | |
75 | { | |
76 | return container_of(obj, struct etnaviv_gem_object, base); | |
77 | } | |
78 | ||
79 | struct etnaviv_gem_ops { | |
80 | int (*get_pages)(struct etnaviv_gem_object *); | |
81 | void (*release)(struct etnaviv_gem_object *); | |
a0a5ab3e | 82 | void *(*vmap)(struct etnaviv_gem_object *); |
a10e2bde | 83 | int (*mmap)(struct etnaviv_gem_object *, struct vm_area_struct *); |
a8c21a54 T |
84 | }; |
85 | ||
86 | static 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 | ||
8779aa8f RK |
93 | struct etnaviv_gem_submit_bo { |
94 | u32 flags; | |
95 | struct etnaviv_gem_object *obj; | |
96 | struct etnaviv_vram_mapping *mapping; | |
97 | }; | |
98 | ||
a8c21a54 T |
99 | /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc, |
100 | * associated with the cmdstream submission for synchronization (and | |
ef146c00 | 101 | * make it easier to unwind when things go wrong, etc). |
a8c21a54 T |
102 | */ |
103 | struct etnaviv_gem_submit { | |
e93b6dee | 104 | struct drm_sched_job sched_job; |
e0329e6c | 105 | struct kref refcount; |
a8c21a54 | 106 | struct etnaviv_gpu *gpu; |
9efabd73 | 107 | struct dma_fence *out_fence, *in_fence; |
8bc4d885 | 108 | int out_fence_id; |
2f9225db LS |
109 | struct list_head node; /* GPU active submit list */ |
110 | struct etnaviv_cmdbuf cmdbuf; | |
8bda1516 | 111 | bool runtime_resumed; |
797b0159 | 112 | u32 exec_state; |
f4a4381b | 113 | u32 flags; |
ef146c00 LS |
114 | unsigned int nr_pmrs; |
115 | struct etnaviv_perfmon_request *pmrs; | |
a8c21a54 | 116 | unsigned int nr_bos; |
8779aa8f | 117 | struct etnaviv_gem_submit_bo bos[0]; |
f4a4381b | 118 | /* No new members here, the previous one is variable-length! */ |
a8c21a54 T |
119 | }; |
120 | ||
e0329e6c LS |
121 | void etnaviv_submit_put(struct etnaviv_gem_submit * submit); |
122 | ||
a8c21a54 T |
123 | int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj, |
124 | struct timespec *timeout); | |
125 | int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags, | |
126 | struct reservation_object *robj, const struct etnaviv_gem_ops *ops, | |
127 | struct etnaviv_gem_object **res); | |
54f09288 | 128 | void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj); |
a8c21a54 T |
129 | struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj); |
130 | void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj); | |
131 | ||
b6325f40 RK |
132 | struct etnaviv_vram_mapping *etnaviv_gem_mapping_get( |
133 | struct drm_gem_object *obj, struct etnaviv_gpu *gpu); | |
134 | void etnaviv_gem_mapping_reference(struct etnaviv_vram_mapping *mapping); | |
135 | void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping); | |
136 | ||
a8c21a54 | 137 | #endif /* __ETNAVIV_GEM_H__ */ |