1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2024, Advanced Micro Devices, Inc. 4 */ 5 6 #ifndef _AMDXDNA_GEM_H_ 7 #define _AMDXDNA_GEM_H_ 8 9 #include <linux/hmm.h> 10 11 struct amdxdna_umap { 12 struct vm_area_struct *vma; 13 struct mmu_interval_notifier notifier; 14 struct hmm_range range; 15 struct work_struct hmm_unreg_work; 16 struct amdxdna_gem_obj *abo; 17 struct list_head node; 18 struct kref refcnt; 19 bool invalid; 20 bool unmapped; 21 }; 22 23 struct amdxdna_mem { 24 u64 userptr; 25 void *kva; 26 u64 dev_addr; 27 size_t size; 28 struct page **pages; 29 u32 nr_pages; 30 struct list_head umap_list; 31 bool map_invalid; 32 }; 33 34 struct amdxdna_gem_obj { 35 struct drm_gem_shmem_object base; 36 struct amdxdna_client *client; 37 u8 type; 38 bool pinned; 39 struct mutex lock; /* Protects: pinned */ 40 struct amdxdna_mem mem; 41 42 /* Below members is uninitialized when needed */ 43 struct drm_mm mm; /* For AMDXDNA_BO_DEV_HEAP */ 44 struct amdxdna_gem_obj *dev_heap; /* For AMDXDNA_BO_DEV */ 45 struct drm_mm_node mm_node; /* For AMDXDNA_BO_DEV */ 46 u32 assigned_hwctx; 47 struct dma_buf *dma_buf; 48 struct dma_buf_attachment *attach; 49 }; 50 51 #define to_gobj(obj) (&(obj)->base.base) 52 #define is_import_bo(obj) ((obj)->attach) 53 54 static inline struct amdxdna_gem_obj *to_xdna_obj(struct drm_gem_object *gobj) 55 { 56 return container_of(gobj, struct amdxdna_gem_obj, base.base); 57 } 58 59 struct amdxdna_gem_obj *amdxdna_gem_get_obj(struct amdxdna_client *client, 60 u32 bo_hdl, u8 bo_type); 61 static inline void amdxdna_gem_put_obj(struct amdxdna_gem_obj *abo) 62 { 63 drm_gem_object_put(to_gobj(abo)); 64 } 65 66 void amdxdna_umap_put(struct amdxdna_umap *mapp); 67 68 struct drm_gem_object * 69 amdxdna_gem_create_object_cb(struct drm_device *dev, size_t size); 70 struct drm_gem_object * 71 amdxdna_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf); 72 struct amdxdna_gem_obj * 73 amdxdna_drm_alloc_dev_bo(struct drm_device *dev, 74 struct amdxdna_drm_create_bo *args, 75 struct drm_file *filp, bool use_vmap); 76 77 int amdxdna_gem_pin_nolock(struct amdxdna_gem_obj *abo); 78 int amdxdna_gem_pin(struct amdxdna_gem_obj *abo); 79 void amdxdna_gem_unpin(struct amdxdna_gem_obj *abo); 80 81 int amdxdna_drm_create_bo_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 82 int amdxdna_drm_get_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 83 int amdxdna_drm_sync_bo_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 84 85 #endif /* _AMDXDNA_GEM_H_ */ 86