drivers/gpu/drm/vmwgfx/ttm_object.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/vmwgfx/ttm_object.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/vmwgfx/ttm_object.c
Extension
.c
Size
17162 bytes
Lines
668
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 ttm_object_file {
	struct ttm_object_device *tdev;
	spinlock_t lock;
	struct list_head ref_list;
	DECLARE_HASHTABLE(ref_hash, VMW_TTM_OBJECT_REF_HT_ORDER);
	struct kref refcount;
};

/*
 * struct ttm_object_device
 *
 * @object_lock: lock that protects idr.
 *
 * This is the per-device data structure needed for ttm object management.
 */

struct ttm_object_device {
	spinlock_t object_lock;
	struct dma_buf_ops ops;
	void (*dmabuf_release)(struct dma_buf *dma_buf);
	struct idr idr;
};

/*
 * struct ttm_ref_object
 *
 * @hash: Hash entry for the per-file object reference hash.
 *
 * @head: List entry for the per-file list of ref-objects.
 *
 * @kref: Ref count.
 *
 * @obj: Base object this ref object is referencing.
 *
 * @ref_type: Type of ref object.
 *
 * This is similar to an idr object, but it also has a hash table entry
 * that allows lookup with a pointer to the referenced object as a key. In
 * that way, one can easily detect whether a base object is referenced by
 * a particular ttm_object_file. It also carries a ref count to avoid creating
 * multiple ref objects if a ttm_object_file references the same base
 * object more than once.
 */

struct ttm_ref_object {
	struct rcu_head rcu_head;
	struct vmwgfx_hash_item hash;
	struct list_head head;
	struct kref kref;
	struct ttm_base_object *obj;
	struct ttm_object_file *tfile;
};

static void ttm_prime_dmabuf_release(struct dma_buf *dma_buf);

static inline struct ttm_object_file *
ttm_object_file_ref(struct ttm_object_file *tfile)
{
	kref_get(&tfile->refcount);
	return tfile;
}

static int ttm_tfile_find_ref_rcu(struct ttm_object_file *tfile,
				  uint64_t key,
				  struct vmwgfx_hash_item **p_hash)
{
	struct vmwgfx_hash_item *hash;

	hash_for_each_possible_rcu(tfile->ref_hash, hash, head, key) {
		if (hash->key == key) {
			*p_hash = hash;
			return 0;
		}
	}
	return -EINVAL;
}

static int ttm_tfile_find_ref(struct ttm_object_file *tfile,
			      uint64_t key,
			      struct vmwgfx_hash_item **p_hash)
{
	struct vmwgfx_hash_item *hash;

	hash_for_each_possible(tfile->ref_hash, hash, head, key) {
		if (hash->key == key) {
			*p_hash = hash;
			return 0;
		}
	}
	return -EINVAL;

Annotation

Implementation Notes