/* * Copyright 2016 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Authors: Christian König
*/ #ifndef __AMDGPU_VM_H__ #define __AMDGPU_VM_H__
/* VMPT level enumerate, and the hiberachy is: * PDB2->PDB1->PDB0->PTB
*/ enum amdgpu_vm_level {
AMDGPU_VM_PDB2,
AMDGPU_VM_PDB1,
AMDGPU_VM_PDB0,
AMDGPU_VM_PTB
};
/* base structure for tracking BO usage in a VM */ struct amdgpu_vm_bo_base { /* constant after initialization */ struct amdgpu_vm *vm; struct amdgpu_bo *bo;
/* protected by bo being reserved */ struct amdgpu_vm_bo_base *next;
/* protected by vm status_lock */ struct list_head vm_status;
/* if the bo is counted as shared in mem stats
* protected by vm status_lock */ bool shared;
/* protected by the BO being reserved */ bool moved;
};
/* provided by hw blocks that can write ptes, e.g., sdma */ struct amdgpu_vm_pte_funcs { /* number of dw to reserve per operation */ unsigned copy_pte_num_dw;
/** * struct amdgpu_vm_update_params * * Encapsulate some VM table update parameters to reduce * the number of function parameters *
*/ struct amdgpu_vm_update_params {
/** * @adev: amdgpu device we do this update for
*/ struct amdgpu_device *adev;
/** * @vm: optional amdgpu_vm we do this update for
*/ struct amdgpu_vm *vm;
/** * @immediate: if changes should be made immediately
*/ bool immediate;
/** * @unlocked: true if the root BO is not locked
*/ bool unlocked;
/** * @pages_addr: * * DMA addresses to use for mapping
*/
dma_addr_t *pages_addr;
/** * @job: job to used for hw submission
*/ struct amdgpu_job *job;
/** * @num_dw_left: number of dw left for the IB
*/ unsignedint num_dw_left;
/** * @needs_flush: true whenever we need to invalidate the TLB
*/ bool needs_flush;
/** * @allow_override: true for memory that is not uncached: allows MTYPE * to be overridden for NUMA local memory.
*/ bool allow_override;
/** * @tlb_flush_waitlist: temporary storage for BOs until tlb_flush
*/ struct list_head tlb_flush_waitlist;
};
struct amdgpu_vm_update_funcs { int (*map_table)(struct amdgpu_bo_vm *bo); int (*prepare)(struct amdgpu_vm_update_params *p, struct amdgpu_sync *sync); int (*update)(struct amdgpu_vm_update_params *p, struct amdgpu_bo_vm *bo, uint64_t pe, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags); int (*commit)(struct amdgpu_vm_update_params *p, struct dma_fence **fence);
};
struct amdgpu_vm_fault_info { /* fault address */
uint64_t addr; /* fault status register */
uint32_t status; /* which vmhub? gfxhub, mmhub, etc. */ unsignedint vmhub;
};
/* buffers that requested this placement but are currently evicted */
uint64_t evicted;
};
struct amdgpu_vm { /* tree of virtual addresses mapped */ struct rb_root_cached va;
/* Lock to prevent eviction while we are updating page tables * use vm_eviction_lock/unlock(vm)
*/ struct mutex eviction_lock; bool evicting; unsignedint saved_flags;
/* Lock to protect vm_bo add/del/move on all lists of vm */
spinlock_t status_lock;
/* Memory statistics for this vm, protected by status_lock */ struct amdgpu_mem_stats stats[__AMDGPU_PL_NUM];
/* Per-VM and PT BOs who needs a validation */ struct list_head evicted;
/* BOs for user mode queues that need a validation */ struct list_head evicted_user;
/* PT BOs which relocated and their parent need an update */ struct list_head relocated;
/* per VM BOs moved, but not yet updated in the PT */ struct list_head moved;
/* All BOs of this VM not currently in the state machine */ struct list_head idle;
/* regular invalidated BOs, but not yet updated in the PT */ struct list_head invalidated;
/* BO mappings freed, but not yet updated in the PT */ struct list_head freed;
/* BOs which are invalidated, has been updated in the PTs */ struct list_head done;
/* Flag to indicate if VM tables are updated by CPU or GPU (SDMA) */ bool use_cpu_for_update;
/* Functions to use for VM table updates */ conststruct amdgpu_vm_update_funcs *update_funcs;
/* Up to 128 pending retry page faults */
DECLARE_KFIFO(faults, u64, 128);
/* Points to the KFD process VM info */ struct amdkfd_process_info *process_info;
/* List node in amdkfd_process_info.vm_list_head */ struct list_head vm_list_node;
/* Valid while the PD is reserved or fenced */
uint64_t pd_phys_addr;
/* Some basic info about the task */ struct amdgpu_task_info *task_info;
/* Store positions of group of BOs */ struct ttm_lru_bulk_move lru_bulk_move; /* Flag to indicate if VM is used for compute */ bool is_compute_context;
/* Memory partition number, -1 means any partition */
int8_t mem_id;
/* cached fault info */ struct amdgpu_vm_fault_info fault_info;
};
/* controls how VM page tables are updated for Graphics and Compute. * BIT0[= 0] Graphics updated by SDMA [= 1] by CPU * BIT1[= 0] Compute updated by SDMA [= 1] by CPU
*/ int vm_update_mode;
/* PASID to VM mapping, will be used in interrupt context to * look up VM of a page fault
*/ struct xarray pasids; /* Global registration of recent page fault information */ struct amdgpu_vm_fault_info fault_info;
};
/** * amdgpu_vm_tlb_seq - return tlb flush sequence number * @vm: the amdgpu_vm structure to query * * Returns the tlb flush sequence number which indicates that the VM TLBs needs * to be invalidated whenever the sequence number change.
*/ staticinline uint64_t amdgpu_vm_tlb_seq(struct amdgpu_vm *vm)
{ unsignedlong flags;
spinlock_t *lock;
/* * Workaround to stop racing between the fence signaling and handling * the cb. The lock is static after initially setting it up, just make * sure that the dma_fence structure isn't freed up.
*/
rcu_read_lock();
lock = vm->last_tlb_flush->lock;
rcu_read_unlock();
/* * vm eviction_lock can be taken in MMU notifiers. Make sure no reclaim-FS * happens while holding this lock anywhere to prevent deadlocks when * an MMU notifier runs in reclaim-FS context.
*/ staticinlinevoid amdgpu_vm_eviction_lock(struct amdgpu_vm *vm)
{
mutex_lock(&vm->eviction_lock);
vm->saved_flags = memalloc_noreclaim_save();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.