1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright © 2022 Intel Corporation 4 */ 5 6 #ifndef _XE_BO_TYPES_H_ 7 #define _XE_BO_TYPES_H_ 8 9 #include <linux/iosys-map.h> 10 11 #include <drm/drm_gpusvm.h> 12 #include <drm/drm_pagemap.h> 13 #include <drm/ttm/ttm_bo.h> 14 #include <drm/ttm/ttm_device.h> 15 #include <drm/ttm/ttm_placement.h> 16 17 #include "xe_device_types.h" 18 #include "xe_ggtt_types.h" 19 20 struct xe_device; 21 struct xe_mem_pool_node; 22 struct xe_vm; 23 24 #define XE_BO_MAX_PLACEMENTS 3 25 26 /* TODO: To be selected with VM_MADVISE */ 27 #define XE_BO_PRIORITY_NORMAL 1 28 29 /** 30 * struct xe_bo - Xe buffer object 31 */ 32 struct xe_bo { 33 /** @ttm: TTM base buffer object */ 34 struct ttm_buffer_object ttm; 35 /** @backup_obj: The backup object when pinned and suspended (vram only) */ 36 struct xe_bo *backup_obj; 37 /** @parent_obj: Ref to parent bo if this a backup_obj */ 38 struct xe_bo *parent_obj; 39 /** @dma_buf: Imported dma-buf ref to keep its resv alive. */ 40 struct dma_buf *dma_buf; 41 /** @flags: flags for this buffer object */ 42 u32 flags; 43 /** @vm: VM this BO is attached to, for extobj this will be NULL */ 44 struct xe_vm *vm; 45 /** @tile: Tile this BO is attached to (kernel BO only) */ 46 struct xe_tile *tile; 47 /** @placements: valid placements for this BO */ 48 struct ttm_place placements[XE_BO_MAX_PLACEMENTS]; 49 /** @placement: current placement for this BO */ 50 struct ttm_placement placement; 51 /** @ggtt_node: Array of GGTT nodes if this BO is mapped in the GGTTs */ 52 struct xe_ggtt_node *ggtt_node[XE_MAX_TILES_PER_DEVICE]; 53 /** @vmap: iosys map of this buffer */ 54 struct iosys_map vmap; 55 /** @kmap: TTM bo kmap object for internal use only. Keep off. */ 56 struct ttm_bo_kmap_obj kmap; 57 /** @pinned_link: link to present / evicted list of pinned BO */ 58 struct list_head pinned_link; 59 #ifdef CONFIG_PROC_FS 60 /** 61 * @client: @xe_drm_client which created the bo 62 */ 63 struct xe_drm_client *client; 64 /** 65 * @client_link: Link into @xe_drm_client.objects_list 66 */ 67 struct list_head client_link; 68 #endif 69 /** @attr: User controlled attributes for bo */ 70 struct { 71 /** 72 * @attr.atomic_access: type of atomic access bo needs 73 * protected by bo dma-resv lock 74 */ 75 u32 atomic_access; 76 } attr; 77 /** 78 * @pxp_key_instance: PXP key instance this BO was created against. A 79 * 0 in this variable indicates that the BO does not use PXP encryption. 80 */ 81 u32 pxp_key_instance; 82 83 /** @freed: List node for delayed put. */ 84 struct llist_node freed; 85 /** @update_index: Update index if PT BO */ 86 int update_index; 87 /** @created: Whether the bo has passed initial creation */ 88 bool created; 89 90 /** @ccs_cleared: true means that CCS region of BO is already cleared */ 91 bool ccs_cleared; 92 93 /** @bb_ccs: BB instructions of CCS read/write. Valid only for VF */ 94 struct xe_mem_pool_node *bb_ccs[XE_SRIOV_VF_CCS_CTX_COUNT]; 95 96 /** 97 * @cpu_caching: CPU caching mode. Currently only used for userspace 98 * objects. Exceptions are system memory on DGFX, which is always 99 * WB. 100 */ 101 u16 cpu_caching; 102 103 /** @devmem_allocation: SVM device memory allocation */ 104 struct drm_pagemap_devmem devmem_allocation; 105 106 /** @vram_userfault_link: Link into @mem_access.vram_userfault.list */ 107 struct list_head vram_userfault_link; 108 109 /** 110 * @min_align: minimum alignment needed for this BO if different 111 * from default 112 */ 113 u64 min_align; 114 115 /** 116 * @purgeable: Purgeability state and accounting. 117 * 118 * All fields are protected by the BO's dma-resv lock. 119 */ 120 struct { 121 /** 122 * @purgeable.state: BO purgeability state 123 * (WILLNEED/DONTNEED/PURGED). 124 */ 125 u32 state; 126 127 /** 128 * @purgeable.vma_count: Number of VMAs currently mapping this BO. 129 */ 130 u32 vma_count; 131 132 /** 133 * @purgeable.willneed_count: Number of active WILLNEED holders. 134 * 135 * Counts WILLNEED VMAs plus active dma-buf exports for 136 * non-imported BOs. The BO flips to DONTNEED on a 1->0 137 * transition only when VMAs still exist; if the last VMA is 138 * removed, the previous BO state is preserved. 139 */ 140 u32 willneed_count; 141 } purgeable; 142 }; 143 144 #endif 145