2 * Copyright (C) 2015 Etnaviv Project
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.
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
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/>.
17 #ifndef __ETNAVIV_GEM_H__
18 #define __ETNAVIV_GEM_H__
20 #include <linux/reservation.h>
21 #include "etnaviv_cmdbuf.h"
22 #include "etnaviv_drv.h"
25 struct etnaviv_gem_ops
;
26 struct etnaviv_gem_object
;
28 struct etnaviv_gem_userptr
{
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
;
45 struct etnaviv_gem_object
{
46 struct drm_gem_object base
;
47 const struct etnaviv_gem_ops
*ops
;
52 struct list_head gem_node
;
53 struct etnaviv_gpu
*gpu
; /* non-null if active */
61 /* normally (resv == &_resv) except for imported bo's */
62 struct reservation_object
*resv
;
63 struct reservation_object _resv
;
65 struct list_head vram_list
;
67 /* cache maintenance */
70 struct etnaviv_gem_userptr userptr
;
74 struct etnaviv_gem_object
*to_etnaviv_bo(struct drm_gem_object
*obj
)
76 return container_of(obj
, struct etnaviv_gem_object
, base
);
79 struct etnaviv_gem_ops
{
80 int (*get_pages
)(struct etnaviv_gem_object
*);
81 void (*release
)(struct etnaviv_gem_object
*);
82 void *(*vmap
)(struct etnaviv_gem_object
*);
83 int (*mmap
)(struct etnaviv_gem_object
*, struct vm_area_struct
*);
86 static inline bool is_active(struct etnaviv_gem_object
*etnaviv_obj
)
88 return atomic_read(&etnaviv_obj
->gpu_active
) != 0;
93 struct etnaviv_gem_submit_bo
{
95 struct etnaviv_gem_object
*obj
;
96 struct etnaviv_vram_mapping
*mapping
;
99 /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
100 * associated with the cmdstream submission for synchronization (and
101 * make it easier to unwind when things go wrong, etc).
103 struct etnaviv_gem_submit
{
104 struct kref refcount
;
105 struct etnaviv_gpu
*gpu
;
106 struct dma_fence
*out_fence
, *in_fence
;
107 struct list_head node
; /* GPU active submit list */
108 struct etnaviv_cmdbuf cmdbuf
;
109 bool runtime_resumed
;
112 unsigned int nr_pmrs
;
113 struct etnaviv_perfmon_request
*pmrs
;
115 struct etnaviv_gem_submit_bo bos
[0];
116 /* No new members here, the previous one is variable-length! */
119 void etnaviv_submit_put(struct etnaviv_gem_submit
* submit
);
121 int etnaviv_gem_wait_bo(struct etnaviv_gpu
*gpu
, struct drm_gem_object
*obj
,
122 struct timespec
*timeout
);
123 int etnaviv_gem_new_private(struct drm_device
*dev
, size_t size
, u32 flags
,
124 struct reservation_object
*robj
, const struct etnaviv_gem_ops
*ops
,
125 struct etnaviv_gem_object
**res
);
126 void etnaviv_gem_obj_add(struct drm_device
*dev
, struct drm_gem_object
*obj
);
127 struct page
**etnaviv_gem_get_pages(struct etnaviv_gem_object
*obj
);
128 void etnaviv_gem_put_pages(struct etnaviv_gem_object
*obj
);
130 struct etnaviv_vram_mapping
*etnaviv_gem_mapping_get(
131 struct drm_gem_object
*obj
, struct etnaviv_gpu
*gpu
);
132 void etnaviv_gem_mapping_reference(struct etnaviv_vram_mapping
*mapping
);
133 void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping
*mapping
);
135 #endif /* __ETNAVIV_GEM_H__ */