drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
Extension
.c
Size
84980 bytes
Lines
3202
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct amdgpu_prt_cb {

	/**
	 * @adev: amdgpu device
	 */
	struct amdgpu_device *adev;

	/**
	 * @cb: callback
	 */
	struct dma_fence_cb cb;
};

/**
 * struct amdgpu_vm_tlb_seq_struct - Helper to increment the TLB flush sequence
 */
struct amdgpu_vm_tlb_seq_struct {
	/**
	 * @vm: pointer to the amdgpu_vm structure to set the fence sequence on
	 */
	struct amdgpu_vm *vm;

	/**
	 * @cb: callback
	 */
	struct dma_fence_cb cb;
};

/**
 * amdgpu_vm_assert_locked - check if VM is correctly locked
 * @vm: the VM which schould be tested
 *
 * Asserts that the VM root PD is locked.
 */
static void amdgpu_vm_assert_locked(struct amdgpu_vm *vm)
{
	dma_resv_assert_held(vm->root.bo->tbo.base.resv);
}

/* Initialize the amdgpu_vm_bo_status object */
static void amdgpu_vm_bo_status_init(struct amdgpu_vm_bo_status *lists)
{
	INIT_LIST_HEAD(&lists->evicted);
	INIT_LIST_HEAD(&lists->moved);
	INIT_LIST_HEAD(&lists->idle);
}

/*
 * Make sure we have the lock to modify the vm_bo status and return the object
 * with the status lists.
 */
static struct amdgpu_vm_bo_status *
amdgpu_vm_bo_lock_lists(struct amdgpu_vm_bo_base *vm_bo)
{
	struct amdgpu_vm *vm = vm_bo->vm;
	struct amdgpu_bo *bo = vm_bo->bo;

	if (amdgpu_vm_is_bo_always_valid(vm, bo)) {
		/* No extra locking needed, protected by the root PD resv lock */
		amdgpu_vm_assert_locked(vm);

		if (bo->tbo.type == ttm_bo_type_kernel)
			return &vm->kernel;

		return &vm->always_valid;
	}

	spin_lock(&vm_bo->vm->individual_lock);
	return &vm->individual;
}

/* Eventually unlock the status list lock again */
static void amdgpu_vm_bo_unlock_lists(struct amdgpu_vm_bo_base *vm_bo)
{
	if (amdgpu_vm_is_bo_always_valid(vm_bo->vm, vm_bo->bo))
		amdgpu_vm_assert_locked(vm_bo->vm);
	else
		spin_unlock(&vm_bo->vm->individual_lock);
}

/**
 * amdgpu_vm_is_bo_always_valid - check if the BO is VM always valid
 *
 * @vm: VM to test against.
 * @bo: BO to be tested.
 *
 * Returns true if the BO shares the dma_resv object with the root PD and is
 * always guaranteed to be valid inside the VM.
 */
bool amdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo)

Annotation

Implementation Notes