File Index
Files and directories
Sign in
FILE

xe_userptr.h

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/xe/xe_userptr.h C
  1/* SPDX-License-Identifier: MIT */
  2/*
  3 * Copyright © 2025 Intel Corporation
  4 */
  5
  6#ifndef _XE_USERPTR_H_
  7#define _XE_USERPTR_H_
  8
  9#include <linux/list.h>
 10#include <linux/mutex.h>
 11#include <linux/notifier.h>
 12#include <linux/scatterlist.h>
 13#include <linux/spinlock.h>
 14
 15#include <drm/drm_gpusvm.h>
 16
 17struct xe_vm;
 18struct xe_vma;
 19struct xe_userptr_vma;
 20
 21/** struct xe_userptr_vm - User pointer VM level state */
 22struct xe_userptr_vm {
 23	/**
 24	 * @userptr.repin_list: list of VMAs which are user pointers,
 25	 * and needs repinning. Protected by @lock.
 26	 */
 27	struct list_head repin_list;
 28	/**
 29	 * @userptr.invalidated_lock: Protects the
 30	 * @userptr.invalidated list.
 31	 */
 32	spinlock_t invalidated_lock;
 33	/**
 34	 * @userptr.invalidated: List of invalidated userptrs, not yet
 35	 * picked
 36	 * up for revalidation. Protected from access with the
 37	 * @invalidated_lock. Removing items from the list
 38	 * additionally requires @lock in write mode, and adding
 39	 * items to the list requires either the @svm.gpusvm.notifier_lock in
 40	 * write mode, OR @lock in write mode.
 41	 */
 42	struct list_head invalidated;
 43};
 44
 45/** struct xe_userptr - User pointer */
 46struct xe_userptr {
 47	/** @invalidate_link: Link for the vm::userptr.invalidated list */
 48	struct list_head invalidate_link;
 49	/** @userptr: link into VM repin list if userptr. */
 50	struct list_head repin_link;
 51	/**
 52	 * @pages: gpusvm pages for this user pointer.
 53	 */
 54	struct drm_gpusvm_pages pages;
 55	/**
 56	 * @notifier: MMU notifier for user pointer (invalidation call back)
 57	 */
 58	struct mmu_interval_notifier notifier;
 59
 60	/**
 61	 * @initial_bind: user pointer has been bound at least once.
 62	 * write: vm->svm.gpusvm.notifier_lock in read mode and vm->resv held.
 63	 * read: vm->svm.gpusvm.notifier_lock in write mode or vm->resv held.
 64	 */
 65	bool initial_bind;
 66#if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
 67	u32 divisor;
 68#endif
 69};
 70
 71#if IS_ENABLED(CONFIG_DRM_GPUSVM)
 72void xe_userptr_remove(struct xe_userptr_vma *uvma);
 73int xe_userptr_setup(struct xe_userptr_vma *uvma, unsigned long start,
 74		     unsigned long range);
 75void xe_userptr_destroy(struct xe_userptr_vma *uvma);
 76
 77int xe_vm_userptr_pin(struct xe_vm *vm);
 78int __xe_vm_userptr_needs_repin(struct xe_vm *vm);
 79int xe_vm_userptr_check_repin(struct xe_vm *vm);
 80int xe_vma_userptr_pin_pages(struct xe_userptr_vma *uvma);
 81int xe_vma_userptr_check_repin(struct xe_userptr_vma *uvma);
 82#else
 83static inline void xe_userptr_remove(struct xe_userptr_vma *uvma) {}
 84
 85static inline int xe_userptr_setup(struct xe_userptr_vma *uvma,
 86				   unsigned long start, unsigned long range)
 87{
 88	return -ENODEV;
 89}
 90
 91static inline void xe_userptr_destroy(struct xe_userptr_vma *uvma) {}
 92
 93static inline int xe_vm_userptr_pin(struct xe_vm *vm) { return 0; }
 94static inline int __xe_vm_userptr_needs_repin(struct xe_vm *vm) { return 0; }
 95static inline int xe_vm_userptr_check_repin(struct xe_vm *vm) { return 0; }
 96static inline int xe_vma_userptr_pin_pages(struct xe_userptr_vma *uvma) { return -ENODEV; }
 97static inline int xe_vma_userptr_check_repin(struct xe_userptr_vma *uvma) { return -ENODEV; };
 98#endif
 99
100#if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
101void xe_vma_userptr_force_invalidate(struct xe_userptr_vma *uvma);
102#else
103static inline void xe_vma_userptr_force_invalidate(struct xe_userptr_vma *uvma)
104{
105}
106#endif
107#endif
~/ Read-only file preview.