The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 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> |
| 21 | #include "etnaviv_drv.h" |
| 22 | |
Lucas Stach | 6e2b98c | 2017-03-22 13:00:53 +0100 | [diff] [blame] | 23 | struct dma_fence; |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 24 | struct etnaviv_gem_ops; |
| 25 | struct etnaviv_gem_object; |
| 26 | |
| 27 | struct etnaviv_gem_userptr { |
| 28 | uintptr_t ptr; |
Lucas Stach | b2295c2 | 2017-11-17 14:16:10 +0100 | [diff] [blame] | 29 | struct mm_struct *mm; |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 30 | bool ro; |
| 31 | }; |
| 32 | |
| 33 | struct etnaviv_vram_mapping { |
| 34 | struct list_head obj_node; |
| 35 | struct list_head scan_node; |
| 36 | struct list_head mmu_node; |
| 37 | struct etnaviv_gem_object *object; |
| 38 | struct etnaviv_iommu *mmu; |
| 39 | struct drm_mm_node vram_node; |
| 40 | unsigned int use; |
| 41 | u32 iova; |
| 42 | }; |
| 43 | |
| 44 | struct etnaviv_gem_object { |
| 45 | struct drm_gem_object base; |
| 46 | const struct etnaviv_gem_ops *ops; |
| 47 | struct mutex lock; |
| 48 | |
| 49 | u32 flags; |
| 50 | |
| 51 | struct list_head gem_node; |
| 52 | struct etnaviv_gpu *gpu; /* non-null if active */ |
| 53 | atomic_t gpu_active; |
| 54 | u32 access; |
| 55 | |
| 56 | struct page **pages; |
| 57 | struct sg_table *sgt; |
| 58 | void *vaddr; |
| 59 | |
| 60 | /* normally (resv == &_resv) except for imported bo's */ |
| 61 | struct reservation_object *resv; |
| 62 | struct reservation_object _resv; |
| 63 | |
| 64 | struct list_head vram_list; |
| 65 | |
| 66 | /* cache maintenance */ |
| 67 | u32 last_cpu_prep_op; |
| 68 | |
| 69 | struct etnaviv_gem_userptr userptr; |
| 70 | }; |
| 71 | |
| 72 | static inline |
| 73 | struct etnaviv_gem_object *to_etnaviv_bo(struct drm_gem_object *obj) |
| 74 | { |
| 75 | return container_of(obj, struct etnaviv_gem_object, base); |
| 76 | } |
| 77 | |
| 78 | struct etnaviv_gem_ops { |
| 79 | int (*get_pages)(struct etnaviv_gem_object *); |
| 80 | void (*release)(struct etnaviv_gem_object *); |
Lucas Stach | a0a5ab3 | 2016-01-25 15:47:28 +0100 | [diff] [blame] | 81 | void *(*vmap)(struct etnaviv_gem_object *); |
Lucas Stach | a10e2bde | 2016-04-27 12:27:02 +0200 | [diff] [blame] | 82 | int (*mmap)(struct etnaviv_gem_object *, struct vm_area_struct *); |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | static inline bool is_active(struct etnaviv_gem_object *etnaviv_obj) |
| 86 | { |
| 87 | return atomic_read(&etnaviv_obj->gpu_active) != 0; |
| 88 | } |
| 89 | |
| 90 | #define MAX_CMDS 4 |
| 91 | |
Russell King | 8779aa8 | 2016-01-21 15:20:55 +0000 | [diff] [blame] | 92 | struct etnaviv_gem_submit_bo { |
| 93 | u32 flags; |
| 94 | struct etnaviv_gem_object *obj; |
| 95 | struct etnaviv_vram_mapping *mapping; |
| 96 | }; |
| 97 | |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 98 | /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc, |
| 99 | * associated with the cmdstream submission for synchronization (and |
| 100 | * make it easier to unwind when things go wrong, etc). This only |
| 101 | * lasts for the duration of the submit-ioctl. |
| 102 | */ |
| 103 | struct etnaviv_gem_submit { |
Lucas Stach | e0329e6 | 2017-11-24 11:36:03 +0100 | [diff] [blame^] | 104 | struct kref refcount; |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 105 | struct etnaviv_gpu *gpu; |
Lucas Stach | 9efabd7 | 2017-11-23 18:02:43 +0100 | [diff] [blame] | 106 | struct dma_fence *out_fence, *in_fence; |
Lucas Stach | f4a4381 | 2017-06-27 16:02:51 +0200 | [diff] [blame] | 107 | u32 flags; |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 108 | unsigned int nr_bos; |
Russell King | 8779aa8 | 2016-01-21 15:20:55 +0000 | [diff] [blame] | 109 | struct etnaviv_gem_submit_bo bos[0]; |
Lucas Stach | f4a4381 | 2017-06-27 16:02:51 +0200 | [diff] [blame] | 110 | /* No new members here, the previous one is variable-length! */ |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 111 | }; |
| 112 | |
Lucas Stach | e0329e6 | 2017-11-24 11:36:03 +0100 | [diff] [blame^] | 113 | void etnaviv_submit_put(struct etnaviv_gem_submit * submit); |
| 114 | |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 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); |
Lucas Stach | 54f0928 | 2017-11-17 12:17:14 +0100 | [diff] [blame] | 120 | void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj); |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 121 | struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj); |
| 122 | void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj); |
| 123 | |
Russell King | b6325f4 | 2016-01-21 15:20:50 +0000 | [diff] [blame] | 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); |
| 128 | |
The etnaviv authors | a8c21a5 | 2015-12-03 18:21:29 +0100 | [diff] [blame] | 129 | #endif /* __ETNAVIV_GEM_H__ */ |