1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2015-2018 Etnaviv Project 4 */ 5 6 #ifndef __ETNAVIV_GEM_H__ 7 #define __ETNAVIV_GEM_H__ 8 9 #include <linux/dma-resv.h> 10 #include "etnaviv_cmdbuf.h" 11 #include "etnaviv_drv.h" 12 13 struct dma_fence; 14 struct etnaviv_gem_ops; 15 struct etnaviv_gem_object; 16 17 struct etnaviv_gem_userptr { 18 uintptr_t ptr; 19 struct mm_struct *mm; 20 bool ro; 21 }; 22 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_context *context; 29 struct drm_mm_node vram_node; 30 unsigned int use; 31 u32 iova; 32 }; 33 34 struct etnaviv_gem_object { 35 struct drm_gem_object base; 36 const struct etnaviv_gem_ops *ops; 37 struct mutex lock; 38 39 /* 40 * The actual size that is visible to the GPU, not necessarily 41 * PAGE_SIZE aligned, but should be aligned to GPU page size. 42 */ 43 u32 size; 44 u32 flags; 45 46 struct list_head gem_node; 47 struct etnaviv_gpu *gpu; /* non-null if active */ 48 atomic_t gpu_active; 49 u32 access; 50 51 struct page **pages; 52 struct sg_table *sgt; 53 void *vaddr; 54 55 struct list_head vram_list; 56 57 /* cache maintenance */ 58 u32 last_cpu_prep_op; 59 60 struct etnaviv_gem_userptr userptr; 61 }; 62 63 static inline 64 struct etnaviv_gem_object *to_etnaviv_bo(struct drm_gem_object *obj) 65 { 66 return container_of(obj, struct etnaviv_gem_object, base); 67 } 68 69 struct etnaviv_gem_ops { 70 int (*get_pages)(struct etnaviv_gem_object *); 71 void (*release)(struct etnaviv_gem_object *); 72 void *(*vmap)(struct etnaviv_gem_object *); 73 int (*mmap)(struct etnaviv_gem_object *, struct vm_area_struct *); 74 }; 75 76 static inline bool is_active(struct etnaviv_gem_object *etnaviv_obj) 77 { 78 return atomic_read(&etnaviv_obj->gpu_active) != 0; 79 } 80 81 #define MAX_CMDS 4 82 83 struct etnaviv_gem_submit_bo { 84 u32 flags; 85 u64 va; 86 struct etnaviv_gem_object *obj; 87 struct etnaviv_vram_mapping *mapping; 88 }; 89 90 /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc, 91 * associated with the cmdstream submission for synchronization (and 92 * make it easier to unwind when things go wrong, etc). 93 */ 94 struct etnaviv_gem_submit { 95 struct drm_sched_job sched_job; 96 struct kref refcount; 97 struct etnaviv_file_private *ctx; 98 struct etnaviv_gpu *gpu; 99 struct etnaviv_iommu_context *mmu_context, *prev_mmu_context; 100 struct dma_fence *out_fence; 101 int out_fence_id; 102 struct list_head node; /* GPU active submit list */ 103 struct etnaviv_cmdbuf cmdbuf; 104 struct pid *pid; /* submitting process */ 105 u32 exec_state; 106 u32 flags; 107 unsigned int nr_pmrs; 108 struct etnaviv_perfmon_request *pmrs; 109 unsigned int nr_bos; 110 struct etnaviv_gem_submit_bo bos[]; 111 /* No new members here, the previous one is variable-length! */ 112 }; 113 114 void etnaviv_submit_put(struct etnaviv_gem_submit * submit); 115 116 int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj, 117 struct drm_etnaviv_timespec *timeout); 118 int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags, 119 const struct etnaviv_gem_ops *ops, 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); 123 124 struct etnaviv_vram_mapping *etnaviv_gem_mapping_get( 125 struct drm_gem_object *obj, struct etnaviv_iommu_context *mmu_context, 126 u64 va); 127 void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping); 128 129 #endif /* __ETNAVIV_GEM_H__ */ 130