1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2015-2018 Etnaviv Project
6 #ifndef __ETNAVIV_GEM_H__
7 #define __ETNAVIV_GEM_H__
9 #include <linux/reservation.h>
10 #include "etnaviv_cmdbuf.h"
11 #include "etnaviv_drv.h"
14 struct etnaviv_gem_ops
;
15 struct etnaviv_gem_object
;
17 struct etnaviv_gem_userptr
{
23 struct etnaviv_vram_mapping
{
24 struct list_head obj_node
;
25 struct list_head scan_node
;
26 struct list_head mmu_node
;
27 struct etnaviv_gem_object
*object
;
28 struct etnaviv_iommu
*mmu
;
29 struct drm_mm_node vram_node
;
34 struct etnaviv_gem_object
{
35 struct drm_gem_object base
;
36 const struct etnaviv_gem_ops
*ops
;
41 struct list_head gem_node
;
42 struct etnaviv_gpu
*gpu
; /* non-null if active */
50 /* normally (resv == &_resv) except for imported bo's */
51 struct reservation_object
*resv
;
52 struct reservation_object _resv
;
54 struct list_head vram_list
;
56 /* cache maintenance */
59 struct etnaviv_gem_userptr userptr
;
63 struct etnaviv_gem_object
*to_etnaviv_bo(struct drm_gem_object
*obj
)
65 return container_of(obj
, struct etnaviv_gem_object
, base
);
68 struct etnaviv_gem_ops
{
69 int (*get_pages
)(struct etnaviv_gem_object
*);
70 void (*release
)(struct etnaviv_gem_object
*);
71 void *(*vmap
)(struct etnaviv_gem_object
*);
72 int (*mmap
)(struct etnaviv_gem_object
*, struct vm_area_struct
*);
75 static inline bool is_active(struct etnaviv_gem_object
*etnaviv_obj
)
77 return atomic_read(&etnaviv_obj
->gpu_active
) != 0;
82 struct etnaviv_gem_submit_bo
{
84 struct etnaviv_gem_object
*obj
;
85 struct etnaviv_vram_mapping
*mapping
;
86 struct dma_fence
*excl
;
87 unsigned int nr_shared
;
88 struct dma_fence
**shared
;
91 /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
92 * associated with the cmdstream submission for synchronization (and
93 * make it easier to unwind when things go wrong, etc).
95 struct etnaviv_gem_submit
{
96 struct drm_sched_job sched_job
;
98 struct etnaviv_gpu
*gpu
;
99 struct dma_fence
*out_fence
, *in_fence
;
101 struct list_head node
; /* GPU active submit list */
102 struct etnaviv_cmdbuf cmdbuf
;
103 bool runtime_resumed
;
106 unsigned int nr_pmrs
;
107 struct etnaviv_perfmon_request
*pmrs
;
109 struct etnaviv_gem_submit_bo bos
[0];
110 /* No new members here, the previous one is variable-length! */
113 void etnaviv_submit_put(struct etnaviv_gem_submit
* submit
);
115 int etnaviv_gem_wait_bo(struct etnaviv_gpu
*gpu
, struct drm_gem_object
*obj
,
116 struct timespec
*timeout
);
117 int etnaviv_gem_new_private(struct drm_device
*dev
, size_t size
, u32 flags
,
118 struct reservation_object
*robj
, const struct etnaviv_gem_ops
*ops
,
119 struct etnaviv_gem_object
**res
);
120 void etnaviv_gem_obj_add(struct drm_device
*dev
, struct drm_gem_object
*obj
);
121 struct page
**etnaviv_gem_get_pages(struct etnaviv_gem_object
*obj
);
122 void etnaviv_gem_put_pages(struct etnaviv_gem_object
*obj
);
124 struct etnaviv_vram_mapping
*etnaviv_gem_mapping_get(
125 struct drm_gem_object
*obj
, struct etnaviv_gpu
*gpu
);
126 void etnaviv_gem_mapping_reference(struct etnaviv_vram_mapping
*mapping
);
127 void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping
*mapping
);
129 #endif /* __ETNAVIV_GEM_H__ */