Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 107 lines 3.2 kB view raw
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 <drm/drm_gem_shmem_helper.h> 10#include <linux/hmm.h> 11#include <linux/iova.h> 12#include "amdxdna_pci_drv.h" 13 14struct amdxdna_umap { 15 struct vm_area_struct *vma; 16 struct mmu_interval_notifier notifier; 17 struct hmm_range range; 18 struct work_struct hmm_unreg_work; 19 struct amdxdna_gem_obj *abo; 20 struct list_head node; 21 struct kref refcnt; 22 bool invalid; 23 bool unmapped; 24}; 25 26struct amdxdna_mem { 27 void *kva; 28 u64 dma_addr; 29 size_t size; 30 struct list_head umap_list; 31 bool map_invalid; 32 /* 33 * Cache the first mmap uva as PASID addr, which can be accessed by driver 34 * without taking notifier_lock. 35 */ 36 u64 uva; 37}; 38 39struct amdxdna_gem_obj { 40 struct drm_gem_shmem_object base; 41 struct amdxdna_client *client; 42 u8 type; 43 bool pinned; 44 struct mutex lock; /* Protects: pinned, mem.kva, open_ref */ 45 struct amdxdna_mem mem; 46 int open_ref; 47 48 /* Below members are initialized when needed */ 49 struct drm_mm mm; /* For AMDXDNA_BO_DEV_HEAP */ 50 struct drm_mm_node mm_node; /* For AMDXDNA_BO_DEV */ 51 u32 assigned_hwctx; 52 struct dma_buf *dma_buf; 53 struct dma_buf_attachment *attach; 54 55 /* True, if BO is managed by XRT, not application */ 56 bool internal; 57}; 58 59#define to_gobj(obj) (&(obj)->base.base) 60#define is_import_bo(obj) ((obj)->attach) 61 62static inline struct amdxdna_gem_obj *to_xdna_obj(struct drm_gem_object *gobj) 63{ 64 return container_of(gobj, struct amdxdna_gem_obj, base.base); 65} 66 67struct amdxdna_gem_obj *amdxdna_gem_get_obj(struct amdxdna_client *client, 68 u32 bo_hdl, u8 bo_type); 69static inline void amdxdna_gem_put_obj(struct amdxdna_gem_obj *abo) 70{ 71 drm_gem_object_put(to_gobj(abo)); 72} 73 74void *amdxdna_gem_vmap(struct amdxdna_gem_obj *abo); 75u64 amdxdna_gem_uva(struct amdxdna_gem_obj *abo); 76u64 amdxdna_gem_dev_addr(struct amdxdna_gem_obj *abo); 77 78static inline u64 amdxdna_dev_bo_offset(struct amdxdna_gem_obj *abo) 79{ 80 return amdxdna_gem_dev_addr(abo) - amdxdna_gem_dev_addr(abo->client->dev_heap); 81} 82 83static inline u64 amdxdna_obj_dma_addr(struct amdxdna_gem_obj *abo) 84{ 85 return amdxdna_pasid_on(abo->client) ? amdxdna_gem_uva(abo) : abo->mem.dma_addr; 86} 87 88void amdxdna_umap_put(struct amdxdna_umap *mapp); 89 90struct drm_gem_object * 91amdxdna_gem_create_shmem_object_cb(struct drm_device *dev, size_t size); 92struct drm_gem_object * 93amdxdna_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf); 94struct amdxdna_gem_obj * 95amdxdna_drm_create_dev_bo(struct drm_device *dev, 96 struct amdxdna_drm_create_bo *args, struct drm_file *filp); 97 98int amdxdna_gem_pin_nolock(struct amdxdna_gem_obj *abo); 99int amdxdna_gem_pin(struct amdxdna_gem_obj *abo); 100void amdxdna_gem_unpin(struct amdxdna_gem_obj *abo); 101 102int amdxdna_drm_create_bo_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 103int amdxdna_drm_get_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 104int amdxdna_drm_sync_bo_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 105int amdxdna_drm_get_bo_usage(struct drm_device *dev, struct amdxdna_drm_get_array *args); 106 107#endif /* _AMDXDNA_GEM_H_ */